#!/bin/bash #author:skycheng #parameters db_user=dbuser db_pass=dbpass db_host=xxx.xxx.xxx.xxx database=database #get current date string datestr=`date +'%Y-%m-%d'` start_time=`date +'%Y-%m-%d %H:%M:%S'` table_name='inf_log_err_'`date +'%Y%m%d'` #get logfile name logfile='/var/log/fs/get_err_record_'$datestr'.log' if [ ! -f $logfile ] then sudo touch $logfile sudo chmod 666 $logfile fi tmplogfile='/var/log/fs/get_err_record_tmp.log' if [ ! -f $tmplogfile ] then sudo touch $tmplogfile sudo chmod 666 $tmplogfile fi echo starttime:$start_time>>$logfile do_get_record() { query_sql="SELECT created,epid,sub_result,diffnum_sub,client_ip FROM "$table_name" WHERE created BETWEEN DATE_ADD(now() ,INTERVAL -10 MINUTE) AND DATE_ADD(now() ,INTERVAL 0 MINUTE) ORDER BY created DESC" mysql -u$db_user -h$db_host -p$db_pass $database -e "$query_sql"|sed 1d>$tmplogfile if [ $? -eq 0 ] then records_counts=`cat $tmplogfile|wc -l` if [ $records_counts -ge 10 ] then rdate=`sed -n '1'p $tmplogfile|awk -F " " '{print $1}'` rtime=`sed -n '1'p $tmplogfile|awk -F " " '{print $2}'` epid=`sed -n '1'p $tmplogfile|awk -F " " '{print $3}'` sub_result=`sed -n '1'p $tmplogfile|awk -F " " '{print $4}'` diffnum_sub=`sed -n '1'p $tmplogfile|awk -F " " '{print $5}'` client_ip=`sed -n '1'p $tmplogfile|awk -F " " '{print $6}'` echo $records_counts'|rdate='$rdate $rtime 'epid='$epid 'sub_result='$sub_result' diffnum_sub='$diffnu m_sub' client_ip='$client_ip else echo $records_counts fi else exit 1 fi } do_get_record