1. 程式人生 > >OGG運維優化腳本(十五)-信息同步類--錯誤日誌同步

OGG運維優化腳本(十五)-信息同步類--錯誤日誌同步

ogg oracle goldengate 腳本 數據同步 shell

文件:logtitle.sh log.sh

路徑:$HOME/ggscript/gginfo

該腳本主要用於每小時檢查ggserr.log內包含error關鍵字的信息(具體可調整)

然後拼接成html格式文件發送給監控網站

該腳本需要配合crontab計劃任務使用


logtile.sh 每月月初執行一次,生成文件頭

#!/bin/bash
cd $HOME
if [ -f .profile ];then
        . .profile
fi

if [ -f .bash_profile ];then
        . .bash_profile
fi

mydate=`date +20%y-%m-%d-%H`
hn=`echo $HOSTNAME`
usr=`echo $USER`

year=`date +%Y`
month=`date +%m`
day=`date +%d`
hour=`date +%H`


echo "HOSTNAME:" $hn"<br>" > $HOME/gglog/gginfo/$hn-$usr.gglog
echo "user:" $usr"<br>" >> $HOME/gglog/gginfo/$hn-$usr.gglog
echo "date:" $mydate"<br>" >> $HOME/gglog/gginfo/$hn-$usr.gglog
echo "<table border="1">" >> $HOME/gglog/gginfo/$hn-$usr.gglog

#cat ggserr.log | egrep ‘‘$year‘-‘$month‘-‘$day‘ ‘$hour‘:[0-59]‘|egrep "ERROR|error"
echo "<tr>" >> $HOME/gglog/gginfo/$hn-$usr.gglog
echo "<td>time</td>" >> $HOME/gglog/gginfo/$hn-$usr.gglog
echo "<td>log</td>" >> $HOME/gglog/gginfo/$hn-$usr.gglog
echo "</tr>" >> $HOME/gglog/gginfo/$hn-$usr.gglog

log.sh 每小時第59分鐘執行一次,過濾日誌中的error信息

#!/bin/bash
cd $HOME
if [ -f .profile ];then
        . .profile
fi

if [ -f .bash_profile ];then
        . .bash_profile
fi

mydate=`date +20%y-%m-%d-%H`
hn=`echo $HOSTNAME`
usr=`echo $USER`

year=`date +%Y`
month=`date +%m`
day=`date +%d`
hour=`date +%H`

cd $HOME/ggserver

cat ggserr.log | egrep ‘‘$year‘-‘$month‘-‘$day‘ ‘$hour‘:[0-59]‘|egrep "ERROR|error" > $HOME/gglog/gginfo/gglog2
cd $HOME/gglog/gginfo
num=`sed -n ‘$=‘ gglog2`

sed ‘s/$/<br>/‘ gglog2 > gglog
if [ ! -n "$num" ];then
	/bin/bash $HOME/ggscript/ggupload/upload.sh log149 $HOME/gglog/gginfo/$hn-$usr.gglog sysinfo
        exit 2
else
echo "<tr>" >> $HOME/gglog/gginfo/$hn-$usr.gglog
echo "<td>$mydate</td>" >> $HOME/gglog/gginfo/$hn-$usr.gglog
echo "<td>`cat gglog`</td>" >> $HOME/gglog/gginfo/$hn-$usr.gglog
echo "</tr>" >> $HOME/gglog/gginfo/$hn-$usr.gglog
fi
echo "</table>" >>  $HOME/gglog/gginfo/$hn-$usr.gglog


/bin/bash $HOME/ggscript/ggupload/upload.sh log149 $HOME/gglog/gginfo/$hn-$usr.gglog sysinfo

sed ‘/table>/d‘ $hn-$usr.gglog > tmp
cat tmp > $hn-$usr.gglog
rm -f $HOME/gglog/gginfo/tmp
rm -f $HOME/gglog/gginfo/gglog2
rm -f $HOME/gglog/gginfo/gglog


本文出自 “netsman” 博客,請務必保留此出處http://netsman.blog.51cto.com/5750076/1939624

OGG運維優化腳本(十五)-信息同步類--錯誤日誌同步