Scripting: Access a website every 5 minutes, if the access is successful, save the access record to the log, if the access fails, send mail to the specified mailbox

Source: Internet
Author: User

Today, due to business needs, to check whether the company's website can be accessed by the external network, under the guidance of colleagues to do a planning task, first of all need to understand the needs:

Visit the company website every five minutes once, if the access is successful, save the access record to the log, and if the access fails, send the message to the specified mailbox.

Need to get, how to achieve it?

How to achieve this function, in the next dull, do not think, certainly is crontab this function, so directly write a script (level limited to this morning), the script is as follows:

[Email protected]

*/5 * * * * Curl http://www.baidu.com

This certainly not, and finally I asked some active in the group of Daniel, they gave guidance, and finally combined with their comments and their own search data finally resolved, the script content is as follows:

#! /bin/bash
#定义变量
L= "web is good!"
#获取网站状态特征码 @1
Ll= ' curl-i-S http://www.baidu.com | head-1 | Cut-d ""-f2 "
#做判断
if [$LL = "200"]
Then
echo "$L" >>/tmp/acc ' date +%f/%h/%m '. Log
elif [$LL = "301"]
Then
echo "$L" >>/tmp/acc ' date +%f/%h/%m '. Log
elif [$LL = "302"]
Then
echo "$L" >>/tmp/acc ' date +%f/%h/%m '. Log
Else
echo "not find the page." | Mail-s "not find the page" "[Email protected]"
Fi

@1: Web Site Status Signature: If the returned value is 200, 301, 302 represents a successful visit to the site

The script is finished, and the following is a much simpler task to write.

Crontab-e

*/5 * * * */usr/jihuarenwu.sh

Note that the jihuarenwu.sh to have execute permissions.

Because the level is low now, have found new method will revise immediately, if Netizen has good method please inform.

In this thanks: Guangzhou-greedy, Shenzhen-sam, Nanjing-Yun, Amin, Jiangsu-Kite, Royal Park + bean dish, wait, Budweiser little Prince and other friends of the guidance.

Scripting: Access a website every 5 minutes, if the access is successful, save the access record to the log, if the access fails, send mail to the specified mailbox

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.