do_writelog i "日志文件($log_filename),初始化读取日志行数:$log_new_count,退出执行"
else
log_old_count=$(cat $tmpsdir/$log_md5sum)
expr $log_old_count + 0 &>/dev/null
if [ $? -ne 0 ];then
do_writelog e "日志文件($log_filename),读取历史行数失败,退出执行"
exit 0
fi
log_new_count=$(wc -l $log_filename|awk '{print $1}')
if [ $log_new_count -eq $log_old_count ];then
do_writelog i "日志文件($log_filename),未更新,退出执行"
exit 0
elif [ $log_new_count -lt $log_old_count ];then
do_writelog i "日志文件($log_filename),跨日更新日志行数:$log_new_count,退出执行"
echo "$log_new_count" >$tmpsdir/$log_md5sum
else
log_upd_count=$(expr $log_new_count - $log_old_count)
do_writelog i "日志文件($log_filename),历史行数:$log_old_count,最新行数:$log_new_count,更新行数:$log_upd_count"
#读取更新的日志
log_content=$(tail -n +`expr $log_old_count + 1` $log_filename|head -n +$log_upd_count)
oldIFS=$IFS
IFS="|"
count=0
for i in $log_gjz;do
if [ $(echo "$log_content"|grep -c -w "$i") -ge 1 ];then
let count+=1
fi
if [ $count -gt 0 ];then
break
fi
done
IFS=$oldIFS
if [ $count -gt 0 ];then
echo "0" >>$tmpsdir/${log_md5sum}.retry
else
do_writelog i "日志文件($log_filename),未获取到关键字,退出执行"
echo "$log_new_count" >$tmpsdir/$log_md5sum
exit 0
fi
if [[ $(wc -l $tmpsdir/${log_md5sum}.retry|awk '{print $1}') -gt $log_retry ]];then
echo "0" >>$tmpsdir/${log_md5sum}_$(date +%F)
if [ $(wc -l $tmpsdir/${log_md5sum}_$(date +%F)|awk '{print $1}') -le $log_max ];then
$stops_command 1>>$logfile 2>&1
$start_command 1>>$logfile 2>&1
do_writelog i "日志文件($log_filename),日志内容:$log_content,找到关键字:$i,停止命令:$stops_command,启动命令:$start_command,重启服务"