脚本专栏 
首页 > 脚本专栏 > 浏览文章

一个shell for循环与case结合的脚本(监控程序状态)

(编辑:jimmy 日期: 2024/5/10 浏览:3 次 )

核心代码:

复制代码 代码如下:
#/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语句、if语句使用介绍
下一篇:bash脚本输入密码不回显问题的解决方法
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网