代码改变世界

OGG 自动重启脚本

2019-07-13 16:03  那个,我  阅读(1260)  评论(0编辑  收藏  举报
从朋友那里得来的OGG 重启脚本,感觉很好用,分享给大家。

定时任务

00 6-20 * * * /oggdata/log/oggautorestart.sh >/oggdata/log/crontab_oggautorestart.log 2>&1
[说明]  因为晚上可以有维护操作,我们不希望在维护期间OGG 自动跑起来

脚本

oggautorestart.sh

#!/bin/bash
if [ -f ~/.bash_profile ];
then
      . ~/.bash_profile
fi

#OGG 目录
OGGHOME=/oggdata
#创建日志目录
if [ ! -d $OGGHOME/log ]; then
   mkdir $OGGHOME/log;
fi

cd $OGGHOME/log
echo "Start checking ......begin time: `date +'%Y%m%d %H:%M:%S'`" >> $OGGHOME/log/all.log
echo "info all"|$OGGHOME/ggsci|grep -E "MANAGER" >> $OGGHOME/log/status.all
echo "info all"|$OGGHOME/ggsci |grep -E "REPLICAT|EXTRACT" >> $OGGHOME/log/status.all

cat $OGGHOME/log/status.all | while read line
do
hhh=`echo $line | awk '{print $1}'`
sss=`echo $line | awk '{print $2}'`
nnn=`echo $line | awk '{print $3}'`

if [ "$hhh" = "MANAGER" ]
then
       if [ "$sss" != "RUNNING" ]
       then
               echo "$hhh is not running......start begin time: `date +'%Y%m%d %H:%M:%S'`" >> $OGGHOME/log/all.log
               echo "start $hhh" |$OGGHOME/ggsci
       else
               echo "MANAGER is running" >> $OGGHOME/log/ok.all
       fi

else
       if [ "$sss" != "RUNNING" ]
       then
               echo "$nnn is not running......start begin time: `date +'%Y%m%d %H:%M:%S'`" >> $OGGHOME/log/all.log
               echo "start $nnn" |$OGGHOME/ggsci
       else
               echo "$nnn is running" >> $OGGHOME/log/ok.all
       fi
fi

done

> $OGGHOME/log/status.all
> $OGGHOME/log/ok.all
echo "Ending check......end time: `date +'%Y%m%d %H:%M:%S'`" >> $OGGHOME/log/all.log
echo "##################" >> $OGGHOME/log/all.log