shell脚本(15)

shell脚本监测阿帕奇服务状态

**环境准备

准备一台Centos7服务器

系统: Centos7.3

内存:1G

cpu: 2核

IP地址: 10.0.0.41**

vim jk_httpd.sh 
#!/bin/bash
while true
do
    port_num=$(ss -ntl | grep -c 80)
    if [ $port_num -eq 0 ];then
       echo "httpd服务已经停止运行!"
       /usr/local/sbin/mail.py [email protected] "警告! ! "  "httpd服务已经停止运行! "
      num=1
      while [ $num -le 30 ]
      do
          sleep 2
          port_num=$(ss -ntl | grep -c 80)
          if [ $port_num -eq 1 ];then
              echo "httpd服务恢复! "
              /usr/local/sbin/mail.py [email protected] "恢复 " "httpd服务已经恢复运行! "
              break
          fi
          let num++
      done
   fi
   sleep 5
done
sh jk_httpd.sh 
# 停止阿帕奇服务
systemctl stop httpd

在这里插入图片描述

# 启动阿帕奇服务
systemctl start httpd

在这里插入图片描述

发布了68 篇原创文章 · 获赞 24 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/aaronszm/article/details/103986183