shell for循环+case的脚本 一个shell for循环与case结合的脚本(监控程序状态)
人气:0想了解一个shell for循环与case结合的脚本(监控程序状态)的相关内容吗,在本文为您仔细讲解shell for循环+case的脚本的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:shell,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"
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
加载全部内容