Linux shell Script monitoring site 80 port and site is normal

Source: Internet
Author: User

Monitoring website 80 Ports

Many times we do not know whether the site 80 port is normal, of course, my previous Shell monitoring site status (continued) This article can also monitor the site, here is just to provide you with another way to monitor the site.

Script content:

The code is as follows Copy Code

VI check-80.sh

#!/bin/bash
NMAP-P0-P80-SS-VV Blog.slogra.com|grep |tail-n1>/tmp/nmap.txt
Check_80= ' Cat/tmp/nmap.txt|awk ' {print $} '
If ["$check _80"!= "open"]; Then
Body= "Www.111cn.net Port is error!"
subject= "blog.slogra.com Port Down,check it now! @from Monitor ' date +%t '"
echo "${body}" | Mutt-s "${subject}" rocdk@163.com
Fi

Shell script monitors site for normal

1. Write shell script, save to/opt/http_monitor

The code is as follows Copy Code

#!/bin/bash

#网站url地址
Url= "http://www.111cn.net/"

#获取http响应代码
Http_code= ' Curl-o/dev/null-s-w '%{http_code} ' ' ${url} '
#echo $HTTP _code

#服务器能正常响应, you should return code of 200.
If [$HTTP _code!=];then
#重启服务
Service httpd Restart
Fi

2. Add to Crontab, adding new tasks using the CRONTAB-E command:

Shell Code

The code is as follows Copy Code
#每分钟运行一次
*/1 * * * */opt/http_monitor

3. Stop service, test, cool! A minute later, it's automatically started! But the Chinese garbled, check the original is not loaded system variables, good to do, in http_monitor add locale environment variables can be:

Shell Code

The code is as follows Copy Code

Export LC_ALL=ZH_CN. UTF-8


Attention

Many friends use dnspod monitoring, but it can only monitor whether the server can be connected, if the site is poisoned may not be monitored.

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.