Linux - shell脚本之 判断Apache是否启动

  判断Apache是否启动,启动,记录日志;未启动,记录日志,并重启

#!/bin/bash

# Desc: 检测Apache是否启动,如果没有启动,记录日志,并启动
# Author: NangongYi
# Time: 2019/11/05 18:33

# 获取Apache的状态,赋予is_open变量
is_open=$(nmap -sT 192.168.18.128 | grep tcp | grep http | awk '{print $2}')

# 判断,如果Apache开启,记录日志;如果未开,重启,记录日志
if [ "$is_open" == "open" ]
        then
                echo "$(date) httpd is ok!" >> /tmp/httpd.acc.log
        else
                /etc/rc.d/init.d/httpd restart &>/dev/null
                echo "$(date) httpd is restart!" >> /tmp/httpd.err.log
fi

# The End
发布了59 篇原创文章 · 获赞 2 · 访问量 5574

猜你喜欢

转载自blog.csdn.net/LDR1109/article/details/102956818