Linux shell監控網站存活,服務埠,資料庫警報腳本

#防止被郵件系統遮罩

用linux自帶的mail的命令發郵箱,經常的被各大郵箱服務給遮罩,尤其是qq和sina的~~~

所以改用mutt登錄163的郵箱,然後在發警報的郵件。這樣的話就不會被遮罩了,怎麼說163mail也是個牌子~~~~~~~ 我用的是安卓的,郵箱是 網易郵箱 下面是網易的安卓郵箱apk包,我感覺挺不錯的……………

mutt的方式,也可以在nagios用的……

http://as.baidu.com/a/item?docid=649780501&f=web_a...

這個是mutt的配置腳本,裡面已經集成了一個163的帳號和密碼~~~~~~~~~~ 這是我隨便創建的,方便大家直接報警發郵件,當然了,大家也可以改成自己的郵箱密碼什麼的~~~~~~~!!!

  1. #!/bin/bash
  2. #info : ruifengyunceshi@163.com 7256958
  3. wget http://rfyiamcool.googlecode.com/files/msmtp-1.4.1...
  4. tar xjvf msmtp-1.4.18.tar.bz2
  5. cd msmtp-1.4.18
  6. ./configure --prefix=/usr/local/msmtp
  7. make
  8. make install
  9. ln -s /usr/local/msmtp/bin/msmtp /bin/msmtp
  10. mkdir -p /usr/local/msmtp/etc
  11. cat >> /usr/local/msmtp/etc/msmtprc <<EOF
  12. account default
  13. host smtp.163.com
  14. from ruifengyunceshi@163.com
  15. auth login
  16. port 25
  17. user ruifengyunceshi@163.com
  18. password 7256958
  19. tls off
  20. syslog on
  21. EOF
  22. cd ~
  23. cat >> muttrc <<EOF
  24. set sendmail="/usr/local/msmtp/bin/msmtp"
  25. set use_from=yes
  26. set from=ruifengyunceshi@163.com
  27. set envelope_from=yes
  28. EOF
  29. cat >> /etc/Muttrc.local <<EOF
  30. /bin/msmtp —host=smtp.163.com —domain=163.com —auth=plain —user=7256958-f=ruifengyunceshi@163.com -t ruifengyunceshi@163.com -d
  31. EOF
  32. echo "hello"|mutt -s "baojing" 123l@163.com

這個是報警的腳本,監控網址的~~~

  1. #!/bin/bash
  2. while true
  3. do
  4. url="http://10.10.10.22/index.html"
  5. status=$(/usr/bin/curl -s --head "$url"| awk '/HTTP/ {print $2}')
  6. if [ "$status" != "200" ]; then
  7. echo "bad"
  8. echo "not 200"|mutt -s "baojing" 123l@163.com
  9. else
  10. echo "good"
  11. fi
  12. sleep 10
  13. done

保存為

  1. vi baojing.sh
  2. sh baojing.sh &

這個是監控遠端的埠的,比如80 110 25 1723 等等埠

  1. #!/bin/bash
  2. while true
  3. do
  4. newip1=120.92.251.18
  5. date=$(date -d "today" +"%Y-%m-%d_%H:%M:%S")
  6. newport=80
  7. #kkk()
  8. #{
  9. # nmap -sT $newip -p $newport | grep open
  10. #}
  11. if ! nmap -sT $newip1 -p $newport | grep open
  12. then
  13. echo " $newip1 is bad ${date}" |mutt -s "baojing" 123l@163.com
  14. else
  15. echo "web is good"
  16. fi
  17. sleep 10
  18. done

這個是監控mysql的從伺服器狀態的~

  1. #!/bin/bash
  2. mima=123123
  3. while true
  4. do
  5. mysql -uroot -p$mima -e “show slave status\G;” | grep -i Running | egrep “IO|SQL” | grep -i yes | wc -l >/root/num
  6. if [ $(cat /root/num) -eq 2 ]; then
  7. echo “mysql slave is running ok !!”
  8. else
  9. echo " $newip1 is bad" |mutt -s "mysql is bad" 123l@163.com
  10. fi
  11. done

本文出自 “峰雲,就她了。” 博客,請務必保留此出處http://rfyiamcool.blog.51cto.com/1030776/910970

arrow
arrow

    Johnson峰 發表在 痞客邦 留言(0) 人氣()