shell脚本监控ogg进程状态插入mysql数据库

因为ogg monitor监控软件配置版本问题,使用shell脚本监控ogg进程状态,脚本如下:

#!/bin/bash

cd /opt/ogg

export tmpfile=/opt/oggtemp

(echo info all;echo exit)|./ggsci|grep -E "EXTRACT|REPLICAT|MANAGER" |awk 'BEGIN {FS=" +"} {print $1,$3,$2,$4,$5}' >> $tmpfile

user="root"

password="xxxxxx"

host="192.168.xx.xx"

mysql_conn="mysql -h"$host" -u"$user" -p"$password""

updatetime=$(date "+%Y-%m-%d %H:%M:%S")

cat $tmpfile | while read type name status lagChkpt timeChkpt

    do

if [ "$type" = "MANAGER" ]; then

        $mysql_conn -e "INSERT INTO sink.sink_jdbc_ogg_stats values(UUID(),'test','MANAGER','$name','$type','00:00:00','00:00:00','$updatetime')"

        continue

else

        $mysql_conn -e "INSERT INTO sink.sink_jdbc_ogg_stats values(UUID(),'test','$type','$status','$name','$lagChkpt','$timeChkpt','$updatetime')"

        continue

fi

    done

cat /dev/null > $tmpfile

然后配置crontab定时启动(注意赋予脚本执行权限 chmod +x ),定时获取ogg状态

你可能感兴趣的:(shell脚本监控ogg进程状态插入mysql数据库)