Shell scripts--monitoring Web services

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.