monit_riak.sh

96
乔伊斯
2017.04.10 16:54* 字数 207

#!/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="songyingjun@qq.com"

ccAddress="songyingjun@qq.com"

echo "" > /usr/tmp/alert_mail_record

while true

do

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

date_now=`date +%Y%m%d%H`

sent_mail=`grep "$date_nowreStart Riak unSuccessful" /usr/tmp/alert_mail_record`

if [ "$process_check" ="0" ] && [ "$sent_mail" = "" ];then

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

if [ "$?" ="0" ];then

echo"`date +%Y%m%d%H%M%S` SendEmail Successful..." >>/usr/tmp/alert_mail_record

fi

sudo /usr/sbin/riakstart

sudo /usr/sbin/riak-csstart

sleep 60

riak_cs_statu=`sudo/usr/sbin/riak-cs ping`

riak_statu=`sudo /usr/sbin/riak ping`

if ["$riak_cs_statu" = "pong" ] && ["$riak_statu" = "pong" ];then

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

else

echo"`date +%Y%m%d%H` reStart Riak unSuccessful..." >/usr/tmp/alert_mail_record

fi

fi

sleep 30

done

日记本