1.監控端口nginx
#!/bin/bashweb
##############################################################bash
# File Name: web.shcurl
# Version: V7.4ide
# Author: feng yuurl
# Organization: https://blog.51cto.com/13520761spa
# Created Time : 2018-03-27 15:05:09code
# Description:blog
##############################################################進程
if [ $(netstat -lntup | grep -w 80| awk -F "[ :]+" 'NR==1{print $5}') = 80 ];then
echo "Nginx is Running"
else
echo "Nginx is Stopped"
mail -s "Nginx is stop" q@163.com < nginx is stop
fi
2.監控進程(注意:監控進程,腳本名不要寫服務名)
#!/bin/bash
##############################################################
# File Name: web1.sh
# Version: V7.4
# Author: feng yu
# Organization: https://blog.51cto.com/13520761
# Created Time : 2018-03-27 15:30:56
# Description:
##############################################################
if [ $(ps -ef | grep nginx |wc -l) -gt 0 ];then
echo "Nginx is Running"
else
echo "Nginx is stopped"
mail -s "nginx is stop" q@163.com < nginx is stop
fi
3.返回值
#!/bin/bash
##############################################################
# File Name: web2.sh
# Version: V7.4
# Author: feng yu
# Organization: https://blog.51cto.com/13520761
# Created Time : 2018-03-27 16:01:40
# Description:
##############################################################
num=$(curl -I www.baidu.com -s -w %{http_code} -o /dev/null)
if [ $num = 200 ];then
echo "網頁正常"
else
echo "$num"
mail -s "網頁異常" q@163.com < 網頁異常,$num
fi