手机
当前位置:查字典教程网 >脚本专栏 >linuxshell >一个shell for循环与case结合的脚本(监控程序状态)
一个shell for循环与case结合的脚本(监控程序状态)
摘要:核心代码:复制代码代码如下:#/bin/bashset-xHOSTS="nginxmysqlphp-cgi"formyhostin$HOST...

核心代码:

复制代码 代码如下:

#/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结合的脚本(监控程序状态)】相关文章:

Linux中执行shell脚本的4种方法总结

如何编写健壮的Bash脚本(经验分享)

shell脚本学习与总结

一个监控网卡流量的shell脚本

Shell脚本获取进程的运行时间

Shell实现系统时间和BIOS时间同步校准脚本分享

shell写的告警次数控制及恢复示例代码

一天一个shell命令 linux好管家-进程-ps命令详解

shell 编程中空格的使用方法

Shell脚本实现监控MySQL主从同步

精品推荐
分类导航