写一个脚本检查Apache进程是否存在,若不存在则显示不存在,若存在则显示进程个数,当不等于10个时用红色字体通知管理员,并询问管理员是否启动Apache服务。

复制代码 代码如下:
#!/bin/bash
#echo "$(service httpd status)"
PIDNUM=$(pgrep httpd | wc -l)
if [[ $PIDNUM -eq 0 ]];then
        echo "Apache is stopped."
        read -p "Do you want to start Apache" START
        if [[ $START == y ]];then
                echo "$(service httpd start)"
        else
                echo "You refused to start Apache."
        fi   
else
        echo "Apache is running. Proccess number is $PIDNUM."
        if [[ $PIDNUM != 10 ]];then
                echo -e "\033[31mPID didn't equal 10\033[0m"
        fi 
fi

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com