监控进程脚本

字数 155阅读 40

#!/bin/bash

node=`ip addr|grep -v 127.0.0.|grep -w inet|awk -F'/' '{print $1}'|awk '{printf $2","}'`

TitleA="LF/Riak-cs node ${node} Statu  Not OK "

TitleB="LF/Riak-cs node ${node} Statu  OK "

To="songyingjun1@qq.com"

ccAddress="songyingjun1@qq.com"

process_check=`/bin/netstat -tunpl|grep beam.smp|grep 8098|wc -l`

rm -f /usr/tmp/alert_mail_record

while true

do

if [ "$process_check" != 1 ];then

sudo /usr/sbin/riak-admin cluster status|sudo /usr/bin/mail -s "$TitleA" -c "$ccAddress" $To

    if [ $? -eq 0 ];then

    echo "`date` SendEmail Successful..." >> /usr/tmp/alert_mail_record

    fi

sudo /usr/sbin/riak start

    if [ $? -eq 0 ];then

    sudo /usr/sbin/riak-admin cluster status|sudo /usr/bin/mail -s "$TitleB" -c "$ccAddress" $To

    else

    echo "`date` Start Riak unSuccessful..." >> /usr/tmp/alert_mail_record

    fi

fi

sleep 30

done

推荐阅读更多精彩内容