1. Monitoring Port
#!/bin/bash
##############################################################
# File Name:web.sh
# version:v7.4
# Author:feng Yu
# organization:http://blog.51cto.com/13520761
# Created Time:2018-03-27 15:05:09
# Description:
##############################################################
If [$ (netstat-lntup | grep-w 80| awk-f "[:]+" ' Nr==1{print $} ') =];then
echo "Nginx is Running"
Else
echo "Nginx is Stopped"
Mail-s "Nginx is stop" [email protected] < Nginx is stop
Fi
2. Monitoring process (note: monitoring process, pin name do not write service names)
#!/bin/bash
##############################################################
# File Name:web1.sh
# version:v7.4
# Author:feng Yu
# organization:http://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" [email protected] < Nginx is stop
Fi
3. Return value
#!/bin/bash
##############################################################
# File Name:web2.sh
# version:v7.4
# Author:feng Yu
# organization:http://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 =];then
echo "Web Normal"
Else
echo "$num"
Mail-s "Page exception" [Email protected] < page exception, $num
Fi
Shell scripts--monitoring Web services