Linux - Apache shell script to determine whether the start

  Determining whether to start Apache, start log; not started, log, and restarting

#!/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

 

Published 59 original articles · won praise 2 · Views 5574

Guess you like

Origin blog.csdn.net/LDR1109/article/details/102956818