Shell Script Monitor Site page normal open _linux shell

Source: Internet
Author: User
Tags curl egrep

Now in order to save money, I used a shell script, simply write a monitoring. By Curl a fixed page of 200 status code, if it is 200, said the site is normal, if not 200 automatically restart the site, and then send mail to QQ mailbox. QQ on their own at the same time, through the micro-letter can also receive the alarm, not only can receive the alarm, but also to solve the problem. Basically, you can also troubleshoot the web.

Copy Code code as follows:

#! /bin/bash
Source/etc/profile
A= "web is good!"
ip= ' Ifconfig eth0 | grep "inet addr" | Awk-f "[:]+" ' {print $} '
Tt1= ' curl-i-S http://xx.8x.18x.xx:1657/product/pro_detail_-rg000785.shtml | head-1 | Cut-d ""-f2 '
Process= ' Ps-ef | grep java | Egrep "TOMCAT1" | Awk-f "" ' {print $} '
if [$tt 1 = "200"]
Then
echo "$A" >>/home/taoyake/scripts/website-error. ' Date +%f '. Log
Else
/opt/tomcat1/bin/shutdown.sh
cd/opt/tomcat1/work/catalina/
RM-RF localhost
Kill-9 $Process
/opt/tomcat1/bin/startup.sh
echo "1657 is reload." >>/home/taoyake/scripts/website-error. ' Date +%f '. Log
echo "1657 is reload." | Mail-s "website-1657" "505065674@qq.com"
Fi

Copy Code code as follows:

more/home/taoyake/scripts/reload_website-1658.sh
#! /bin/bash
Source/etc/profile
B= "1658 is good!"
ip= ' Ifconfig eth0 | grep "inet addr" | Awk-f "[:]+" ' {print $} '
Tt1= ' curl-i-S http://xx.xx.183.xx:1658/product/pro_detail_-rg000785.shtml | head-1 | Cut-d ""-f2 '
Process= ' Ps-ef | grep java | Egrep "TOMCAT2" | Awk-f "" ' {print $} '
if [$tt 1 = "200"]
Then
echo "$B" >>/home/taoyake/scripts/website-1658-access. ' Date +%f '. Log
Else
/opt/tomcat2/bin/shutdown.sh
cd/opt/tomcat2/work/catalina/
RM-RF localhost
Kill-9 $Process
/opt/tomcat2/bin/startup.sh
echo "1658 is reload." >>/home/taoyake/scripts/website-1658-error. ' Date +%f '. Log
echo "1658 is reload." | Mail-s "website-1658" "505065674@qq.com"
Fi
[Root@web ~]# Crontab-l
*/10 * * * */usr/sbin/ntpdate time.windows.com >/dev/null 2>&1
*/5 * * * */bin/sh/home/taoyake/scripts/reload_website.sh >/dev/null 2>&1
*/5 * * * */bin/sh/home/taoyake/scripts/reload_website-1658.sh >/dev/null 2>&1

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.