Shell脚本_判断apache是否启动

 
安装nmap:
 yum install nmap -y
nmap 127.0.0.1
 
脚本
vim apache_is_start.sh

chmod 755 apache_is_start.sh

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash
 
# 判断apache是否启动
# Author:James 2016-10-14
 
# apache所在机器的IP(默认apache端口为80)
ipport=127.0.0.1
 
# 获取apache是否启动状态(通过-w全量匹配tcp的80端口)
isopen=$(nmap $ipport| grep -w 80/tcp | grep http | awk '{print $2}')
 
if [ "$isopen" == "open" ]
   then
        echo "$(date) httpd is ok!" >> /tmp/apache.log
   else
        # 启动apache
        /etc/rc.d/init.d/httpd start &>/dev/null
        echo "$(date) restart httpd!" >> /tmp/apache-err.log
fi

 

 




posted @ 2016-10-14 13:45    阅读(2778)  评论(0编辑  收藏  举报