文件: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
时间: 2024-10-29 19:08:45