Use shell in linux to monitor website status

Source: Internet
Author: User
Tags website server

Our website now uses some tools to monitor whether the website server can be accessed, but not the status of the website. Next I will recommend you to use shell to monitor the website status script in linux.

Today, I wrote shell monitoring for my website, so I don't know if my website goes down. This script checks the webpage status and webpage connection time separately, and can be expanded as needed, very powerful.
Script content:
Vi check-web.sh

The Code is as follows: Copy code
#! /Bin/sh
Weblist =/root/weblist.txt
For list in 'cat $ weblist | grep-E-v "# | ^ $ "'
Do
Httpcode = 'curl-o/dev/null-s-w % {http_code} "$ list "'
Httptime = 'curl-o/dev/null-s-w "time_connect: % {time_connect} ntime_starttransfer: % {time_starttransfer} ntime_total: % {time_total} n "" $ list "| grep time_total | awk-F": "'{print $2*1000 }''
# If [$ httpcode = 200] | [$ httpcode = 301] | [$ httpcode = 302] | [$ httpcode = 403] | [$ httpcode = 401]
If [$ httpcode = 200] | [$ httpcode = 301] | [$ httpcode = 302]
Then
Echo "$ list is checked OK! "
Else
Echo "$ list is down! "| Mutt-s" web is down "rocdk@163.com
Fi
If [$ httptime-ge 10000]
Then
Echo "$ list is timeout! "| Mutt-s" web is timeout "rocdk@163.com
Else
Echo "$ list is connect OK! "
Fi
Done

Then create a list of websites to check, in the http://xxx.xxx.xxx format

The Code is as follows: Copy code
Touch/root/weblist.txt
Http://blog.slogra.com

Chmod + x/root/soft_shell/check-web.sh

Crontab-e
*/3 */bin/sh/root/soft_shell/check-web.sh


The following figure shows the manual operation.



Okay, you can rest assured.

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.