close
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的帳號和密碼~~~~~~~~~~ 這是我隨便創建的,方便大家直接報警發郵件,當然了,大家也可以改成自己的郵箱密碼什麼的~~~~~~~!!!
- #!/bin/bash
- #info : ruifengyunceshi@163.com 7256958
- wget http://rfyiamcool.googlecode.com/files/msmtp-1.4.1...
- tar xjvf msmtp-1.4.18.tar.bz2
- cd msmtp-1.4.18
- ./configure --prefix=/usr/local/msmtp
- make
- make install
- ln -s /usr/local/msmtp/bin/msmtp /bin/msmtp
- mkdir -p /usr/local/msmtp/etc
- cat >> /usr/local/msmtp/etc/msmtprc <<EOF
- account default
- host smtp.163.com
- from ruifengyunceshi@163.com
- auth login
- port 25
- user ruifengyunceshi@163.com
- password 7256958
- tls off
- syslog on
- EOF
- cd ~
- cat >> muttrc <<EOF
- set sendmail="/usr/local/msmtp/bin/msmtp"
- set use_from=yes
- set from=ruifengyunceshi@163.com
- set envelope_from=yes
- EOF
- cat >> /etc/Muttrc.local <<EOF
- /bin/msmtp —host=smtp.163.com —domain=163.com —auth=plain —user=7256958-f=ruifengyunceshi@163.com -t ruifengyunceshi@163.com -d
- EOF
- echo "hello"|mutt -s "baojing" 123l@163.com
這個是報警的腳本,監控網址的~~~
- #!/bin/bash
- while true
- do
- url="http://10.10.10.22/index.html"
- status=$(/usr/bin/curl -s --head "$url"| awk '/HTTP/ {print $2}')
- if [ "$status" != "200" ]; then
- echo "bad"
- echo "not 200"|mutt -s "baojing" 123l@163.com
- else
- echo "good"
- fi
- sleep 10
- done
保存為
- vi baojing.sh
- sh baojing.sh &
這個是監控遠端的埠的,比如80 110 25 1723 等等埠
- #!/bin/bash
- while true
- do
- newip1=120.92.251.18
- date=$(date -d "today" +"%Y-%m-%d_%H:%M:%S")
- newport=80
- #kkk()
- #{
- # nmap -sT $newip -p $newport | grep open
- #}
- if ! nmap -sT $newip1 -p $newport | grep open
- then
- echo " $newip1 is bad ${date}" |mutt -s "baojing" 123l@163.com
- else
- echo "web is good"
- fi
- sleep 10
- done
這個是監控mysql的從伺服器狀態的~
- #!/bin/bash
- mima=123123
- while true
- do
- mysql -uroot -p$mima -e “show slave status\G;” | grep -i Running | egrep “IO|SQL” | grep -i yes | wc -l >/root/num
- if [ $(cat /root/num) -eq 2 ]; then
- echo “mysql slave is running ok !!”
- else
- echo " $newip1 is bad" |mutt -s "mysql is bad" 123l@163.com
- fi
- done
本文出自 “峰雲,就她了。” 博客,請務必保留此出處http://rfyiamcool.blog.51cto.com/1030776/910970
文章標籤
全站熱搜
留言列表