Monitor whether the site can be opened normally by Shell script sharing _linux Shell

Source: Internet
Author: User

Recently, just need to test the stability of the new station, so write a shell script to the local (recently changed MAC), to real-time view you need to monitor the status of the Web page, and sent to the designated mailbox.

Here's a compliment. OS X with crontab scheduled tasks, you can test the script directly on the native ^_^

# VI check_web_alive.sh

Copy Code code as follows:

#!/bin/bash
Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
Export PATH
# define URL
Web_url= ("http://www.example.com" "http://www1.example.com" "http://www2.example.com")

# Check Network
net_alive=$ (ping-c 5 8.8.8.8 |grep ' received ' |awk ' BEGIN {fs= ', "} {print $} ' |awk ' {print $} ')
if [$NET _alive = 0]; Then
echo "Network is not active,please check your network configuration!"
Exit 0
Fi
# Check URL
for ((i=0; i!=${#WEB_URL [@]}; ++i))
{
alive=$ (Curl-o/dev/null-s-M 10-connect-timeout 10-w%{http_code} ${web_url[i]} |grep "000000")
If ["$ALIVE" = = "000000"]; Then
echo "' ${web_url[i]} ' can not be open,please check! | Mail-s "Website Notification to ${web_url[i]}" yourname@example.com
echo "Failed"
Else
echo "' ${web_url[i]} ' is ok!"
Fi
}

Related Article

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.