您现在的位置是:网站首页> 编程资料编程资料
Shell脚本监控服务器在线状态和邮件报警的方法_linux shell_
2023-05-26
403人已围观
简介 Shell脚本监控服务器在线状态和邮件报警的方法_linux shell_
对于服务器来说在线率很重要,出现问题要能及时解决,但系统管理员不能一直守在电脑旁边,通过脚本监控网站出现问题及时通过mail通知管理员,如果是139邮箱还可免费手机短信通知。
注:通过系统直接发送mail容易被拦截,可使用mail连接第三方smtp发送邮件。
shell脚本实现代码:
复制代码 代码如下:
#!/bin/bash
#set -x
while true
do
list=(www.jb51.net s.jb51.net)
mail=jmj@jb51.net
date=$(date -d "today" +"%Y-%m-%d-%H:%M:%S")
i=0
id=${#list[*]}
while [ $i -lt $id ]
do
if ping -c1 ${list[$i]} >/dev/null
then
echo $date:服务器${list[$i]}能ping通。
else
if curl -m 10 ${list[$i]} > /dev/null
then
echo $date:服务器${list[$i]} ping不通,能打开网页。
else
echo "您好,据系统监测服务器${list[$i]}不能访问且ping不通,请及时处理!故障发生时间:$date"|mail -s "服务器${list[$i]}不能连接! 故障发生时间:$date" $mail
until
date=$(date -d "today" +"%Y-%m-%d-%H:%M:%S")
ping -c1 ${list[$i]} >/dev/null && echo "恭喜!服务器${list[$i]}已恢复正常,恢复时间:$date"|mail -s "服务器${list[$i]}已恢复正常! 恢复时间:$date" $mail
do
sleep 5
done
fi
fi
let i++
done
sleep 60
done
您可能感兴趣的文章:
相关内容
- Shell脚本判断IP地址是否合法的方法_linux shell_
- MAC中用Shell脚本批量裁剪各种尺寸的App图标_linux shell_
- 在Shell命令行处理JSON数据的方法_linux shell_
- 用shell脚本在mysql表中批量插入数据的方法_linux shell_
- windows下写的shell脚本在linux执行出错的解决办法_linux shell_
- 用Shell脚本快速搭建Ubuntu下的Nodejs开发环境_linux shell_
- 用内置变量调试shell脚本的方法_linux shell_
- 一个测试下载速度的shell脚本_linux shell_
- 一个下载网页图片的shell脚本_linux shell_
- 杀掉oracle在线用户脚本分享_linux shell_
