shell作业之http交互脚本
2018-12-29 14:48
375 查看
作业
问:编写httpd监控脚本,要求可以输入start|stop|restart|status
答:脚本如下
[code]#!/bin/bash #Date:2018-12-28 #Author:nelws-lcz #Connect:892730644@qq.com #Desc:This script is for http #Version:1.0 while true do echo -e " \033[31m A 开启httpd, \033[0m \033[32m B 停止httpd \033[0m \033[33m C 重启httpd, \033[0m \033[34m D 查看httpd状态 \033[0m \033[35m Q 退出此程序 \033[0m " read -p "请输入你的选择:" char state=`systemctl status httpd | grep "Active" | awk '{print $2}'` state1=`systemctl status httpd | grep "Loaded" | awk '{print $2}'` case $char in a|A) if [ $state == "inactive" ];then if [ $state1 == "not-found" ];then yum install httpd -y >/dev/null firewall-cmd --add-service=http >/dev/null firewall-cmd --reload >/dev/null systemctl start httpd echo "httpd service is installed and running" else systemctl start httpd firewall-cmd --add-service=http >/dev/null firewall-cmd --reload >/dev/null echo "httpd service is running" fi else echo "httpd service is already running" fi ;; b|B) if [ $state == "inactive" ];then echo "httpd service is already stopped" else systemctl stop httpd echo "httpd service has stopped" fi ;; c|C) if [ $state == "inactive" ];then echo "httpd service is not running,what you can do is use command A to start it!" else systemctl restart httpd echo "httpd service has been restarted" fi ;; d|D) if [ $state == "inactive" ];then echo "httpd service is not running" else echo "httpd service is running" fi ;; q|Q) exit 0 ;; *) echo "sorry,you command is not exist,please check!" esac done
测试结果
1.http开启选项(a选项)
1)当http已经开启的时候
2)当http没有开启的时候
3)当http没有开启也没有安装的时候
2.http停止选项
1)http已经开启的时候
2)http已经关闭的时候
3.http重启选项
1)http已经开启的时候
2)http已经关闭的时候
4.http状态选项
1)http已经开启的时候
2)http已经关闭的时候
5.离开选项
6.输入无效命令的时候
bingo~
相关文章推荐
- 统计网卡流量的两段shell脚本(使用ifconfig) 详细出处参考:http://www.jb51.net/article/34290.htm
- shell脚本实现无密码交互的SSH自动登陆
- shell脚本实现无密码交互的SSH自动登陆
- 无交互shell脚本上传文件至服务器
- bash:alias 只能再交互界面用,不能在shell脚本中使用
- shell脚本之通过发送带\n字符串或expect脚本实现交互输入自动化
- 【COCOS2DX-LUA 脚本开发之八】不用CCHttpClient而转用quick-cocos2d-x或cocos2dx-LuaProxy的Lua框架实现Lua-Http网络交互!
- CentOS6.x下通过shell脚本交互安装Web服务 推荐
- 如何用Python交互执行shell脚本
- 作业HTTP服务的监控脚本
- 2015年9月13日-9月15日课程作业(shell)脚本实例
- linux - 怎么自动填写有交互的shell脚本 - SegmentFault
- shell脚本--交互
- Shell脚本交互之:自动输入密码【转】
- Shell 脚本中 curl 取得HTTP返回的状态码
- shell && sql 交互脚本
- 第五周作业 磁盘分区、shell脚本、lvm逻辑卷
- 【COCOS2DX-LUA 脚本开发之八】不用CCHttpClient而转用quick-cocos2d-x或cocos2dx-LuaProxy的Lua框架实现Lua-Http网络交互!
- shell脚本:监控HTTP服务的状态(测试返回码) 推荐
- Linux基本功十一:shell脚本执行及交互