shell监控网站报警脚本
时间:2014-05-21 20:27 来源:linux.it.net.cn 作者:IT网
mail可以是用微信报警,也可以在安卓手机安装个邮件提醒工具,麻烦点的话,可以用移动的飞信,只是现在的智能手机基本都是wcdma和cdma,我周围的人用移动的少,反正大家都是开着网络的,用第三方的邮件提醒就行。
还有就是用linux自带的mail的命令发邮箱,经常的被各大邮箱服务给屏蔽,尤其是qq和sina的~~~
所以改用mutt登录163的邮箱,然后在发报警的邮件。这样的话就不会被屏蔽了,怎么说163mail也是个牌子~~~~~~~ 我用的是安卓的,邮箱是 网易邮箱 下面是网易的安卓邮箱apk包,我感觉挺不错的……………
mutt的方式,也可以在nagios用的……
http://as.baidu.com/a/item?docid=649780501&f=web_alad_1
这个是mutt的配置脚本,里面已经集成了一个163的账号和密码~~~~~~~~~~ 这是我随便创建的,方便大家直接报警发邮件,当然了,大家也可以改成自己的邮箱密码什么的~~~~~~~!!!
1.#!/bin/bash
2.#info : ruifengyunceshi@163.com 7256958
3.wget http://rfyiamcool.googlecode.com/files/msmtp-1.4.18.tar.bz2
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
(责任编辑:IT)
mail可以是用微信报警,也可以在安卓手机安装个邮件提醒工具,麻烦点的话,可以用移动的飞信,只是现在的智能手机基本都是wcdma和cdma,我周围的人用移动的少,反正大家都是开着网络的,用第三方的邮件提醒就行。 还有就是用linux自带的mail的命令发邮箱,经常的被各大邮箱服务给屏蔽,尤其是qq和sina的~~~ 所以改用mutt登录163的邮箱,然后在发报警的邮件。这样的话就不会被屏蔽了,怎么说163mail也是个牌子~~~~~~~ 我用的是安卓的,邮箱是 网易邮箱 下面是网易的安卓邮箱apk包,我感觉挺不错的…………… mutt的方式,也可以在nagios用的…… http://as.baidu.com/a/item?docid=649780501&f=web_alad_1 这个是mutt的配置脚本,里面已经集成了一个163的账号和密码~~~~~~~~~~ 这是我随便创建的,方便大家直接报警发邮件,当然了,大家也可以改成自己的邮箱密码什么的~~~~~~~!!! 1.#!/bin/bash 2.#info : ruifengyunceshi@163.com 7256958 3.wget http://rfyiamcool.googlecode.com/files/msmtp-1.4.18.tar.bz2 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 (责任编辑:IT) |