Shell script to monitor the state of the Linux server website

Source: Internet
Author: User
Tags server website

1, monitor the shell script code of the HTTPD status code.

#!/bin/sh#site:www.jquerycn.cn#website[0]=www.jquerycn.cn/chuzu/'#网站1mobile[0]='13141200000'#对应网站1 Mobile phone number website[1]=www.jquerycn.cn/chushou/'#同上2mobile[1]='13141200000'#同上2 # When the site is large, consider storing it as a file or reading the length from the database=${#website [@]} #获取网站总数量 for((i=0; i< $length; i++)) #循环执行 DoStatus=$ (Curl-i-MTen-o/dev/NULL-s-w%{http_code} ${website[$i]}) #CURL get the HTTP status codeif["$status"X! =" $"X]; Then #检测是否为 $(normal) echo ${website[$i]}'='$status #php/htdoc/jk/shell_monitor.php ${mobile[$i]} ${website[$i]}'=>accesserror!'#执行PHP文件 (using a third-party SMS library, or sending alarm messages) fi #结束ifdone #结束 Do

Execution: CRONTAB-E
Write content: 5 * * * */shell path
(Executes once in 5 minutes)

2. Shell script to monitor website status
Monitor the status of the specified Web page, if return 200 means normal, otherwise error:

#!/bin/bash #edit: www.jquerycn.cn# website URL address #url=$1#获取http响应代码 Http_code= ' Curl-o/dev/NULL-s-w"%{http_code}" "${url}"' #服务器能正常响应, should return 200 of the codeif[$HTTP _code! = $];then Echo $HTTP _code ((a= $HTTP _code/Ten) Echo $a # The exit $a can be handled by the alarmElseExit0fi

Methods to invoke the script:
Bash./url_monitor.sh "http://www.jquerycn.cn/"

Set up crontab Scheduled tasks to be performed every five minutes to monitor the health of the site.
Example:
5 * * * *./url_monitor.sh

Shell script to monitor the state of the Linux server website

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.