教程集 www.jiaochengji.com
教程集 >  脚本编程  >  shell  >  正文 分享一个shell for循环+case的脚本(监控程序状态)

分享一个shell for循环+case的脚本(监控程序状态)

发布时间:2014-08-29   编辑:jiaochengji.com
分享一个shell for循环+case的脚本(监控程序状态)

分享一个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的脚本(监控程序状态)
linux shell学习之shell流程控制
监控Linux服务器网站状态的SHELL脚本
shell监控网站状态 监测网站运行状态的shell脚本
mysql备份与同步脚本
自动监控mysql主从同步的shell脚本代码
shell脚本监控php-fpm并自动重启服务
分析日志统计网站pv 404 500状态码的shell脚本
找出1小时内占用cpu最多的10个进程的shell脚本
Linux Shell判断程序是否运行的代码分享

关键词: for循环   
[关闭]
~ ~