shell监控网站报警脚本
分类:shell编程 阅读:47875 次
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的账号和密码~~~~~~~~~~ 这是我随便创建的,方便大家直接报警发邮件,当然了,大家也可以改成自己的邮箱密码什么的~~~~~~~!!!
#!/bin/bash
#info : ruifengyunceshi@163.com 7256958
wget http://rfyiamcool.googlecode.com/files/msmtp-1.4.18.tar.bz2
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
热门推荐
- shell转义符
- shell 按行循环读入文件方法
- shell删除一年前文件的脚本
- 利用shell脚本监控网站状态
- 利用shell脚本拒绝TCP连接数大于20的IP
- 利用shell命令操作Memcached
- shell脚本自动修复mysql损坏的表
- 给力的10个shell命令
- 关于shell重定向
- shell脚本限制用户进程CPU和内存占用率
- shell 快捷键大全
- shell通过ping检测整个网段IP的网络状态脚本
- shell通过TTL返回值判断网段内主机操作系统
- shell检测线上服务器的系统硬件信息
- php-fpm容易假死,shell实现自动重启php服务
- shell线上环境puppet证书异常 重新进行认证脚本
- shell线上服务器之间对比文件是否一致
- shell监控Fastdfs的storage更新延迟报警
- shell自动删除n天前备份角本参考
- SHELL脚本,来实现Nginx服务进程高可用