当前位置:首页 / 编程技术 / 运营维护 / 一个shell for循环与case结合的脚本(监控程序状态)
一个shell for循环与case结合的脚本(监控程序状态)
发布时间:2022/07/10来源:编程网

核心代码:


#/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

分享到:
免责声明:本文仅代表文章作者的个人观点,与本站无关,请读者仅作参考,并自行核实相关内容。文章内容来源于网络,版权归原作者所有,如有侵权请与我们联系,我们将及时删除。
资讯推荐
热门最新
精品工具
全部评论(0)
剩余输入数量90/90
暂无任何评论,欢迎留下你的想法
你可能感兴趣的资讯
换一批