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.