写一个脚本,判断本机的80端口是否开启着,如果开启着什么都不做,如果发现端口不存在,那么重启一下httpd服务,并发邮件通知你自己。脚本写好后,可以每一分钟执行一次,也可以写一个死循环的脚本,30s检测一次。
{{{密码回复可见}}}
{{{密码回复可见}}}
0
#port=80
po=80
#mail
ma=abc@139.com
while :;do
rs=`netstat -anlp|awk '$4~/:80$/{print $NF}'`
if [ -z $rs ];then
echo "The port $po is die"|mail -s "message" $ma
service httpd start;
fi
sleep 30
done
po=80
ma=abc@139.com
while :;do
rs=`netstat -anlp|awk '$4~/:80$/{print $NF}'`
if [ -z $rs ];then
echo "The port $po is die"|mail -s "message" $ma
service httpd start;
fi
sleep 30
done
0
# /bin/bash
while : ; do
if grep -q netstat -lnp |grep "80" ;then
else service httpd restart
echo "80meikaiqi" |mail -s "80meikaiqi " 1025781634@qq.com
fi
sleep 30
done
while : ; do
if grep -q netstat -lnp |grep "80" ;then
else service httpd restart
echo "80meikaiqi" |mail -s "80meikaiqi " 1025781634@qq.com
fi
sleep 30
done
0
#!/bin/bash
while :;do
a=`netstat -lnp |grep ":80" >/dev/null`
if [ -z $a ];then
/etc/init.d/httpd restart
echo "xxx" |mail -s "xxx" 123@qq.com
fi
sleep 30
done
while :;do
a=`netstat -lnp |grep ":80" >/dev/null`
if [ -z $a ];then
/etc/init.d/httpd restart
echo "xxx" |mail -s "xxx" 123@qq.com
fi
sleep 30
done
0
#!/bin/bash
while :;do
a=`netstat -lnp |grep ":80"`
if [ -z $a ];then
echo "Http is down" | mail -s baojing 891287870@qq.com
/etc/init.d/httpd restart
fi
sleep 30
done
while :;do
a=`netstat -lnp |grep ":80"`
if [ -z $a ];then
echo "Http is down" | mail -s baojing 891287870@qq.com
/etc/init.d/httpd restart
fi
sleep 30
done
0
[root@OceanV sh]# cat check_httpd.sh
#!/bin/bash
port=80
mail=root@localhost
while true
do
s=`netstat -natp |grep $port >/dev/null`
if [ -z $s ];then
/etc/init.d/httpd restart
echo "httpd is stopped,now start it" |mail -s "restart httpd" $mail
fi
sleep 30
done
#!/bin/bash
port=80
mail=root@localhost
while true
do
s=`netstat -natp |grep $port >/dev/null`
if [ -z $s ];then
/etc/init.d/httpd restart
echo "httpd is stopped,now start it" |mail -s "restart httpd" $mail
fi
sleep 30
done
0
#! /bin/bash
# Monitoring httpd
mail=abc@139.com
if netstat -antp |awk 'NR>=3 {print $4}'|grep -q ':80'
then
echo "nothing" > /dev/null
else
/etc/init.d/httpd restart
echo "httpd restart now" mail -s "httpd restart" $mail
fi
# Monitoring httpd
mail=abc@139.com
if netstat -antp |awk 'NR>=3 {print $4}'|grep -q ':80'
then
echo "nothing" > /dev/null
else
/etc/init.d/httpd restart
echo "httpd restart now" mail -s "httpd restart" $mail
fi
0
#!/bin/bash
##httpd restart
while :;
do
h=`netstat -ntpl |awk '{print $4}'|awk -F: '{print $2}' |grep '80'`
if [ $h -eq '80' ]; then
sleep 30
else
servicr httpd restart
fi
done
##httpd restart
while :;
do
h=`netstat -ntpl |awk '{print $4}'|awk -F: '{print $2}' |grep '80'`
if [ $h -eq '80' ]; then
sleep 30
else
servicr httpd restart
fi
done
0
#!/bin/bash
num=`netstat -lntp | grep “:80” | wc -l`
while true
do
if [ $num -eq 0 ];then
echo "httpd is stopped" | mail -s "httpd need to restart" abc@feifei.com
service httpd restart
fi
sleep 30
done
num=`netstat -lntp | grep “:80” | wc -l`
while true
do
if [ $num -eq 0 ];then
echo "httpd is stopped" | mail -s "httpd need to restart" abc@feifei.com
service httpd restart
fi
sleep 30
done
0
#!/bin/bash
## This script is for checking if port 80 is on.
## Writed by Louis on 2014/08/29 18:27
while :;do
port=`netstat -nlpa|grep 'httpd'|grep ':80'`
port1=`echo $port|awk '{print $4}'|awk -F ':' '{print $4}'`
if [ -z $port1 ]; then
service httpd start &> /dev/null
fi
sleep 30
done
#!/bin/bash
## This script is for checking if port 80 is on.
## Writed by Louis on 2014/08/29 18:27
while :;do
port=`netstat -nlpa|grep 'httpd'|grep ':80'`
port1=`echo $port|awk '{print $4}'|awk -F ':' '{print $4}'`
if [ -z $port1 ]; then
service httpd start &> /dev/null
fi
sleep 30
done
0
本帖最后由 游夜 于 2014-9-4 23:00 编辑
#!/bin/bash
while :;do
netstat -an | grep ':80'
if [ echo $? -ne 0 ];then
service httpd restart
echo "restart httpd service."| mail -s "httpd restart" 275235245@qq.com
fi
sleep 30
done
#!/bin/bash
while :;do
netstat -an | grep ':80'
if [ echo $? -ne 0 ];then
service httpd restart
echo "restart httpd service."| mail -s "httpd restart" 275235245@qq.com
fi
sleep 30
done
0
#! /bin/bash
while :;
do
nmap -sS -vv 192.168.12.107 |grep 80 |tail -n1 > /tmp/nmap.txt #借鉴论坛里的一个帖子
rr80=`cat /tmp/nmap.txt`
if [ "$rr80" = "" ]; then
service httpd restart && mail -s "rr_port_80" abc@163.com < /tmp/nmap.txt
fi
sleep 30
done
while :;
do
nmap -sS -vv 192.168.12.107 |grep 80 |tail -n1 > /tmp/nmap.txt #借鉴论坛里的一个帖子
rr80=`cat /tmp/nmap.txt`
if [ "$rr80" = "" ]; then
service httpd restart && mail -s "rr_port_80" abc@163.com < /tmp/nmap.txt
fi
sleep 30
done
0
#!/bin/bash
while sleep 30
do
if netstat -lnp | grep -q ':80'
then
echo "80 down"
echo "80 down" | mail -s "Alarm" xxx@126.com
/etc/init.d/httpd restart
else
echo "normal" > /dev/mull
fi
done
while sleep 30
do
if netstat -lnp | grep -q ':80'
then
echo "80 down"
echo "80 down" | mail -s "Alarm" xxx@126.com
/etc/init.d/httpd restart
else
echo "normal" > /dev/mull
fi
done
0
#!/bin/bash
port=80
while : ; do
for i in ` netstat -tln | awk '{print $4}' | egrep -v 'Local | only'|awk -F ':' '{print $0}' | sed 's/.*://g'`; do
if [ $i -ne $port ];then
echo "Httpd service is down!" | mail -s chengchengxiyou@126.com
service httpd restart
fi
done
sleep 30
done
port=80
while : ; do
for i in ` netstat -tln | awk '{print $4}' | egrep -v 'Local | only'|awk -F ':' '{print $0}' | sed 's/.*://g'`; do
if [ $i -ne $port ];then
echo "Httpd service is down!" | mail -s chengchengxiyou@126.com
service httpd restart
fi
done
sleep 30
done
0
- #!/bin/bash
- # Monitor httpd scripe.
- # Writen by Wangxiaoqiang 2014.11.24.
- MAIL=xxxxxxxxxxx@xxx.com
- while true
- do
- netstat -lnpt | grep 80 > /dev/null
- if [ $? -ne 0 ]
- then
- service httpd restart > /dev/null
- sleep 5
- netstat -lnpt | grep 80 > /dev/null
- if [ $? -ne 0 ]
- then
- echo "$HOSTNAME web is down" | mail -s "Monitor WEB FOR $HOSTNAME" $MAIL
- else
- echo "$HOSTNAME web is running" | mail -s "Monitor WEB FOR $HOSTNAME" $MAIL
- fi
- fi
- sleep 30
- done
- # End
0
本帖最后由 aqi 于 2014-11-24 16:45 编辑
while :
do
netstat -ntapl | grep ":80"
if [[ $? != 0 ]];then
service httpd restart
echo | mail -s "`hostname` httpd is warning" xxx@xxx.com
fi
sleep 30
done
while :
do
netstat -ntapl | grep ":80"
if [[ $? != 0 ]];then
service httpd restart
echo | mail -s "`hostname` httpd is warning" xxx@xxx.com
fi
sleep 30
done
0
#!/bin/bash
while :; do
netstat -lntp | grep httpd
if [ `echo $?` -eq 0 ];then
sleep 30
else
/etc/init.d/httpd restart
echo "httpd restart" | mail -s "httpd restart" 445043972@qq.com
fi
done
while :; do
netstat -lntp | grep httpd
if [ `echo $?` -eq 0 ];then
sleep 30
else
/etc/init.d/httpd restart
echo "httpd restart" | mail -s "httpd restart" 445043972@qq.com
fi
done
0
#! /bin/bash
# 判断本机的80端口是否开启着,如果开启着什么都不做,如果发现端口不存在,那么重启一下httpd服务,并发邮件通知你自己。
# 脚本写好后,可以每一分钟执行一次,也可以写一个死循环的脚本,30s检测一次。
port=80
mail=zhaohailg@163.com
while :; do
# 查看本机的80端口的连接状态
result=`netstat -lnp |awk '$4 ~/:'$port'$/ {print $NF}'`;
#echo "$result";
#如果80端口没有开启,则开启
if [ -z $result ]; then
echo "The port $port is die!";
/etc/init.d/nginx restart;
else
echo "The port $port is work!";
fi
#没30s执行检测一次
sleep 30;
done
# 判断本机的80端口是否开启着,如果开启着什么都不做,如果发现端口不存在,那么重启一下httpd服务,并发邮件通知你自己。
# 脚本写好后,可以每一分钟执行一次,也可以写一个死循环的脚本,30s检测一次。
port=80
mail=zhaohailg@163.com
while :; do
# 查看本机的80端口的连接状态
result=`netstat -lnp |awk '$4 ~/:'$port'$/ {print $NF}'`;
#echo "$result";
#如果80端口没有开启,则开启
if [ -z $result ]; then
echo "The port $port is die!";
/etc/init.d/nginx restart;
else
echo "The port $port is work!";
fi
#没30s执行检测一次
sleep 30;
done
0
#!/bin/bash
while :; do
open=`netstat -lnp | grep -w 80|wc -l`
if [ "$open" == "0"]; then
/usr/local/apache2/bin/apachectl start
echo "The httpd server was stoped. The server will start right now!" |mail -s "The httpd server was stoped" abc@139.com
fi
done
while :; do
open=`netstat -lnp | grep -w 80|wc -l`
if [ "$open" == "0"]; then
/usr/local/apache2/bin/apachectl start
echo "The httpd server was stoped. The server will start right now!" |mail -s "The httpd server was stoped" abc@139.com
fi
done
0
本帖最后由 wuhen 于 2015-2-18 18:58 编辑
或者写入crontab计划周期任务中 */1 * * * *
- #! /bin/bash
- while :;
- do
- mail=123@123.com
- a=`netstat -lnp |grep ':80'|grep -q 'LISTEN'`
- if [ $? -ne 0 ]
- then
- /etc/init.d/httpd restart >/dev/null 2> /dev/null
- echo "The 80 port is down."|mail -s 'check_80' $mail
- else
- exit 0
- fi
- sleep 60
- done
- #! /bin/bash
- mail=15620609228@163.com
- if netstat -lnp |grep ':80' |grep -q 'LISTEN'; then
- exit
- else
- /etc/init.d/httpd restart >/dev/null 2> /dev/null
- echo "The 80 port is down."|mail -s 'check_80' $mail
- n=`ps aux |grep httpd|grep -cv grep`
- if [ $n -eq 0 ]; then
- /etc/init.d/httpd start 2>/tmp/apache_start.err
- mail -s 'apache_start_error' $mail < /tmp/apache_start.err
- fi
- fi
0
#!/bin/bash
#
ma=abc@139.com
while :; do
a=`netstat -lnp|grep ':80' `
if [ -z $a ] ; then
echo "The port $po is die"|mail -s "message" $ma
service httpd restart;
fi
sleep 30
done
#
ma=abc@139.com
while :; do
a=`netstat -lnp|grep ':80' `
if [ -z $a ] ; then
echo "The port $po is die"|mail -s "message" $ma
service httpd restart;
fi
sleep 30
done
0
#!/bin/bash
#
while true
do
num=`netstat -tulnp | grep 80 |awk '{print $4}'|sed 's/://g'`
if [[ $num == "80" ]];then
echo "httpd is ok"
else
service httpd restart
echo "httpd restart"|mail -s httpd restart root@localhost.localdomain
fi
sleep 30
done
#
while true
do
num=`netstat -tulnp | grep 80 |awk '{print $4}'|sed 's/://g'`
if [[ $num == "80" ]];then
echo "httpd is ok"
else
service httpd restart
echo "httpd restart"|mail -s httpd restart root@localhost.localdomain
fi
sleep 30
done
0
本帖最后由 sss 于 2015-5-28 14:18 编辑
- #!/bin/bash
- #Inspection web Servicei
- #2015/05/15
- while :
- do
- services=netstat -nltp | grep ':80' | awk -F ':' '{print $4}'
- if [ -z $services ]
- then
- service httpd restart >/dev/null 2>&1
- echo " YO YO httpd service reboot "| mail -s "httpd reboot" xxxxxxxxxx@qq.com
- fi
- sleep 30
- done
0
#!/bin/bash
while :
do
a=`netstat -lnp|grep ":80"`
if [-z a];then
/etc/init.d/httpd restart
mail -s "http is down" 111@qq.com
fi
sleep 30
done
while :
do
a=`netstat -lnp|grep ":80"`
if [-z a];then
/etc/init.d/httpd restart
mail -s "http is down" 111@qq.com
fi
sleep 30
done
0
while :
do
nc -t -z -w 2 localhost 80 > /dev/null
case $? in
0)
echo "OK!"
exit
;;
*)
/etc/init.d/httpd restart
echo "It is DOWN of 80 port!" | mail -s "down" m13291298083_2@163.com
;;
esac
sleep 30
done
while :
do
nc -t -z -w 2 localhost 80 > /dev/null
case $? in
0)
echo "OK!"
exit
;;
*)
/etc/init.d/httpd restart
echo "It is DOWN of 80 port!" | mail -s "down" m13291298083_2@163.com
;;
esac
sleep 30
done
0
查看的8080端口 #!/bin/bash while : do q=`lsof -i:8080|awk '{print $2}'|grep -v 'PID'|awk '{print $1}'` if [ -z "$q" ] then echo " number is 8080 ,please deal with it "|mail -s " 8080 service is problem" 18856066058@139.com sh /home/tomcat/bin/startup.sh fi sleep 30 done
0
while :;do a=`netstat -lanp|grep ':80'|awk '{$1 ~ /tcp/} {print $0}'|wc -l` if [ $a != 1 ];then service httpd restart echo "80端口断开,已重启httpd服务" |mail -s test "httpd警告" 506556658@qq.com fi sleep 30000 done
0
while :
do
netstat -lnp |grep 80
a=`echo $?`
if [ $a != 0 ]
then
/usr/local/apache2/bin/apachectl restart
echo "TCP:80 restart" |mail -s "192.168.153.130:80" 123@mail.com
else
echo "TCP:80 is running"
fi
sleep 10
done
do
netstat -lnp |grep 80
a=`echo $?`
if [ $a != 0 ]
then
/usr/local/apache2/bin/apachectl restart
echo "TCP:80 restart" |mail -s "192.168.153.130:80" 123@mail.com
else
echo "TCP:80 is running"
fi
sleep 10
done
0
- #!/bin/bash
- a=`netstat -lnp | grep :80`
- if [ -z "$a" ]
- then
- /etc/init.d/httpd restart
- mail -s "aa" 825536458@qq.com
- fi
0
#!/bin/bash
while true
do
a=`netstat -anltp |grep httpd |awk '{print $4}' |awk -F ':' '{print $4}'`
if [ $a -eq 80 ]
then
echo "it is OK"
else
service httpd start
echo "http has problem" |mail -s httpd xxx@qq.com
fi
sleep 30
done
while true
do
a=`netstat -anltp |grep httpd |awk '{print $4}' |awk -F ':' '{print $4}'`
if [ $a -eq 80 ]
then
echo "it is OK"
else
service httpd start
echo "http has problem" |mail -s httpd xxx@qq.com
fi
sleep 30
done
0
本帖最后由 ヾSun 于 2015-12-21 11:25 编辑
- #!bin/bash
- while [ "1" = "1" ]
- do
- netstat -lnp|grep :80 >80.log
- if [ -s 80.log ]; then
- echo ""
- else
- service httpd start
0
#!/bin/bash
mail=123@qq.com
while :;do
ps1=`ps aux |grep '80'>/dev/null 2>$1
if [ -z $ps1 ];then
echo "The 80 port is down ,please restart!" |mail -s "80_error,restart httpd." $mail
/etc/init.d/httpd restart
else
echo "The 80 port is on,don't worry."
fi
sleep 30
done
mail=123@qq.com
while :;do
ps1=`ps aux |grep '80'>/dev/null 2>$1
if [ -z $ps1 ];then
echo "The 80 port is down ,please restart!" |mail -s "80_error,restart httpd." $mail
/etc/init.d/httpd restart
else
echo "The 80 port is on,don't worry."
fi
sleep 30
done
0
#!/bin/bash
service_status=`nmap -sT 121.42.176.208 | grep 'http$' | awk '{print $2}'`
date=`date`
if [ "$service_status" == "open" ];then
echo "apache的服务运行正常" &> /dev/null
else
/usr/local/apache4/bin/apachectl restart
echo "$date apache服务运行不正常,重新启动apache服务" >> /tmp/error.txt
fi
service_status=`nmap -sT 121.42.176.208 | grep 'http$' | awk '{print $2}'`
date=`date`
if [ "$service_status" == "open" ];then
echo "apache的服务运行正常" &> /dev/null
else
/usr/local/apache4/bin/apachectl restart
echo "$date apache服务运行不正常,重新启动apache服务" >> /tmp/error.txt
fi
0
本帖最后由 hlymlv 于 2016-1-7 15:21 编辑
看看,#!/bin/bash
while :
do
netstat -lnp |grep ':80' |grep -q LISTEN
if [ $? -eq 0 ];then
exit
else
service httpd restart
echo "httpd is not on" |mail -s "apache" 123@321.com
fi
sleep 30
done
不能比啊
看看,#!/bin/bash
while :
do
netstat -lnp |grep ':80' |grep -q LISTEN
if [ $? -eq 0 ];then
exit
else
service httpd restart
echo "httpd is not on" |mail -s "apache" 123@321.com
fi
sleep 30
done
不能比啊
0
for i in `netstat -lnp |grep 80 `; do if[ -z $i];then service httpd restart | mail -s else sleep 30 fi done
0
while true
do
ss=`ps -ef | grep httpd |wc -l`
if [[ ! $ss -gt 1 ]];then
service httpd start mail -s "httpd is down" xxx xxx@qq.com
fi
sleep 30
done
do
ss=`ps -ef | grep httpd |wc -l`
if [[ ! $ss -gt 1 ]];then
service httpd start mail -s "httpd is down" xxx xxx@qq.com
fi
sleep 30
done
编辑回复