分享一个shell for循环+case的脚本(监控程序状态)
分享一个for循环+case的脚本(监控程序状态并执行相关操作) ,供大家学习参考。
复制代码代码如下:
#/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"
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
您可能感兴趣的文章:
bash shell中case语句的例子
学习shell中case的用法
shell脚本case条件控制语句的一个bug