http监控脚本
脚本:
#!/bin/bash
echo -e "
\033[31m start\033[0m
\033[32m stop\033[0m
\033[33m restart\033[0m
\033[34m status\033[0m
"
while true
do
read -p "输入命令:" A
case $A in
start)
ps aux |grep http|grep /usr/sbin &>/dev/null
[ $? == 0 ]&&echo "you needn't start" ||systemctl start httpd &&echo success start
;;
stop)
ps aux |grep http|grep /usr/sbin &>/dev/null
[ $? == 0 ]&& systemctl stop httpd&&echo success stop||echo can not stop
;;
restart)
ps aux |grep http|grep /usr/sbin &>/dev/null
[ $? != 0 ]&&echo you just need start||systemctl restart httpd&&echo success restart
;;
status)
ps aux |grep http|grep /usr/sbin &>/dev/null
[ $? == 0 ]&&systemctl status httpd||echo you neet to start
;;
quit)
exit 0
;;
*)
echo "请输入正确命令!"
;;
esac
done