1.监控端口

#!/bin/bash

##############################################################

# File Name: web.sh

# Version: V7.4

# Author: feng yu

# Organization: https://blog.51cto.com/13520761

# Created Time : 2018-03-27 15:05:09

# Description:

##############################################################

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