发现mysql error 日志中error 信息的脚本

#此脚本在扫描mysql 日志文件,找出含有有error,teminate的日志输出到当前目录下的MysqlMonitorLog.dat中
#此脚本入参为一个mysql实例端口号.
#按以下方式运行此脚本 ./monitor.sh 3308
export filename

filename=MysqlMonitorLog.dat
tempname=MysqlMonitorLogTemp.dat
datadir=./

function WriteIndex()
{
  datadir=./
  time=`date +%Y-%m-%d" "%H:%M:%S`
  firstipadd=`ifconfig -a|grep "inet addr"|awk -F ":" '{print $2}'|egrep "^168|^188"|awk '{if ( NR==1 )print $1}'` #ip address
 
  if [ ! -f  /mysqldata/$1/errlog/mysqld.err_check ];then
   touch /mysqldata/$1/errlog/mysqld.err_check
  fi

  difftest=`diff /mysqldata/$1/errlog/mysqld.err  /mysqldata/$1/errlog/mysqld.err_check | grep -i error;`

  cp /mysqldata/$1/errlog/mysqld.err  /mysqldata/$1/errlog/mysqld.err_check
 
 
  echo -e  ",,$firstipadd,Linux,$1,dblogerr,$time,$difftest">>$datadir$filename
}


WriteIndex  3306 

猜你喜欢

转载自xixiyanqi.iteye.com/blog/2277544