#!/bin/bash
while true
do
echo " start 开启http
stop 关闭http
restart 重启http
status 查看http状态
q | Q 退出脚本"
read -p " 请输入你想要的选择:" char
case $char in
########开启httpd服务###########
start)
if
[ `systemctl status httpd | grep Active | awk '{print $2}'` == inactive ];then
systemctl start httpd
echo -e " \033[31m 开启完毕 \033[0m"
elif
[ `systemctl status httpd | grep Active | awk '{print $2}'` == active ];then
echo -e " \033[31m http服务已经开启,无需再次开启 \033[0m"
fi
;;
########关闭http服务#############
stop)
if
[ `systemctl status httpd | grep Active | awk '{print $2}'` == active ];then
systemctl stop httpd
echo -e " \033[31m 关闭完毕 \033[0m"
elif
[ `systemctl status httpd | grep Active | awk '{print $2}'` == inactive ];then
echo -e " \033[31m http服务已经关闭,无需再次关闭 \033[0m"
fi
;;
########重启http服务############
restart)
systemctl restart httpd
echo -e " \033[31m 重启完毕 \033[0m"
;;
########查看http状态############
status)
echo -en " \033[31m http的状态为:\033[0m"
systemctl status httpd | grep Active | awk '{print $3}' | awk -F\( '{print $2}' | awk -F \) '{print $1}'
;;
########退出脚本########
q|Q)
exit 0
;;
########若输入其他没有的选项######
*)
echo -e " \033[31m 请输入正确的选项 \033[0m"
;;
esac
done