Shell指令碼監控網站頁面正常開啟情況_linux shell

來源:互聯網
上載者:User

現在單位為了省錢,我用了shell指令碼,簡單的寫了一個監控。通過curl一個固定式頁面面的200狀態代碼,如果是200,就說網站是正常的,如果不是200就自動重啟網站,然後發郵件到QQ郵箱。自己在上QQ的同時,通過微信也可以收到警示,不但可以收到警示,還可以解決問題。基本上也可以解決web的故障。

複製代碼 代碼如下:
 
#! /bin/bash
source /etc/profile
A="web is Good !"
ip=`ifconfig eth0 | grep "inet addr" | awk -F "[: ]+" '{print $4}'`
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 $2}'`
if [ $tt1 = "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

複製代碼 代碼如下:

 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 $4}'`
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 $2}'`
if [ $tt1 = "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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.