分享一个shell for循环+case的脚本(监控程序状态)
分享一个for循环+case的脚本(监控程序状态并执行相关操作) ,供大家学习参考。
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的脚本(监控程序状态)
linux shell学习之shell流程控制
监控Linux服务器网站状态的SHELL脚本
shell监控网站状态 监测网站运行状态的shell脚本
mysql备份与同步脚本
Shell 流程控制
shell脚本监控php-fpm并自动重启服务
自动监控mysql主从同步的shell脚本代码
分析日志统计网站pv 404 500状态码的shell脚本
找出1小时内占用cpu最多的10个进程的shell脚本