一个shell for循环与case结合的脚本(监控程序状态)
一个shell for循环与case结合的脚本(监控程序状态)
发布时间:2016-12-28 来源:查字典编辑
摘要:核心代码:复制代码代码如下:#/bin/bashset-xHOSTS="nginxmysqlphp-cgi"formyhostin$HOST...

核心代码:

复制代码 代码如下:

#/bin/bash

set -x

HOSTS="nginx mysql php-cgi"

for myhost in $HOSTS

do

count=(`ps aux |grep $myhost |grep -v grep |wc -l`)

echo "$myhost"

echo "$count"

if [ $count -eq 0 ]; then

case $myhost in

nginx)

cd /usr/local/webserver/nginx/sbin/

./nginx

echo "nginx has be down"

sleep 5

mysql)

/etc/init.d/mysqld start

echo "mysql has be down"

*)

echo "what‘s the hell?"

esac

fi

done

set +x

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新linuxshell学习
热门linuxshell学习
脚本专栏子分类