您的位置:首页 > 运维架构 > Linux

服务器自动发送邮件监测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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  FreeSWITCH linux