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

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

一个shell 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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/3345838.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-10-06
下一篇 2022-10-06

发表评论

登录后才能评论

评论列表(0条)

保存