一个shell for循环与case结合的脚本(监控程序状态)
2019/7/10 21:54:04
本文主要是介绍一个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
这篇关于一个shell for循环与case结合的脚本(监控程序状态)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!