当前位置: 操作系统/服务器>linux
一个shell for循环与case结合的脚本(监控程序状态)
来源: 互联网 发布时间:2014-10-15
本文导语: 核心代码: 代码如下:#/bin/bashset -xHOSTS="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 "n...
核心代码:
代码如下:
#/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