«

Shell脚本判断Apache进程是否存在

时间:2024-3-2 15:59     作者:韩俊     分类: Linux


写一个脚本检查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?(y/n)" 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 "33[31mPID didn't equal 1033[0m"

        fi  

fi

标签: linux

热门推荐