服务器自动发送邮件监测freeswitch进程
2015-06-09 15:59
597 查看
vim /etc/mail.rc 添加
set from=******@163.com smtp=smtp://smtp.163.com:25
set smtp-auth-user=******@163.com smtp-auth-password=****** smtp-auth=login
vim check.sh
#!/bin/bash
source .bash_profile
pip=101.251.251.92
ip=`/sbin/ifconfig eth0 | grep "inet addr" | awk '{print $2}' | awk -F: '{print $2}'`
i=`ps -ef | grep freeswitch | grep -v grep | wc -l`
date=`date`
cpu=`top -b -n 1 | grep Cpu | awk '{print $2}'| cut -f 1 -d "%"`
ping=`ping -c 3 $pip|awk 'NR==7 {print $4}'`
if [ $ping -eq 0 ]
then
text2="$pip status GRASHED"
else
text2="$pip status READY"
fi
if [ $i -lt 1 ]
then
text='Freeswitch is down'
echo "Server: "$ip$'\n'$date$'\n'"CPU used: "$cpu$'\n'"$text2"$'\n'"$text"| mail -s "$ip Abnormal" -a /home/freeswitch/log/freeswitch.log ******@qq.com
#else
#text='Freeswitch is running...'
#echo "Server: "$ip$'\n'$date$'\n'"CPU used: "$cpu$'\n'"$text2"$'\n'"$text"| mail -s "$ip Normal" ******@qq.com
fi
设置每天8-23点,每隔一小时自动执行脚本发送邮件
crontab -e
0 8-23 * * * /root/check.sh
set from=******@163.com smtp=smtp://smtp.163.com:25
set smtp-auth-user=******@163.com smtp-auth-password=****** smtp-auth=login
vim check.sh
#!/bin/bash
source .bash_profile
pip=101.251.251.92
ip=`/sbin/ifconfig eth0 | grep "inet addr" | awk '{print $2}' | awk -F: '{print $2}'`
i=`ps -ef | grep freeswitch | grep -v grep | wc -l`
date=`date`
cpu=`top -b -n 1 | grep Cpu | awk '{print $2}'| cut -f 1 -d "%"`
ping=`ping -c 3 $pip|awk 'NR==7 {print $4}'`
if [ $ping -eq 0 ]
then
text2="$pip status GRASHED"
else
text2="$pip status READY"
fi
if [ $i -lt 1 ]
then
text='Freeswitch is down'
echo "Server: "$ip$'\n'$date$'\n'"CPU used: "$cpu$'\n'"$text2"$'\n'"$text"| mail -s "$ip Abnormal" -a /home/freeswitch/log/freeswitch.log ******@qq.com
#else
#text='Freeswitch is running...'
#echo "Server: "$ip$'\n'$date$'\n'"CPU used: "$cpu$'\n'"$text2"$'\n'"$text"| mail -s "$ip Normal" ******@qq.com
fi
设置每天8-23点,每隔一小时自动执行脚本发送邮件
crontab -e
0 8-23 * * * /root/check.sh
相关文章推荐
- Linux socket 初步
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- 基于 Linux 集群环境上 GPFS 的问题诊断
- 谁是桌面王者?Win PK Linux三大镇山之宝
- vivi下重新调整分区
- Linux VS Unix:Linux欲一统天下 Unix不死
- linux下设定环境变量
- Linux下修改MySQL编码的方法