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.