#!/bin/bash
#检测日志关键字 $1传递日志目录 $2传递关键字
check_wait_log () {
tail -n +0 -vfn0 $1 | while read line;
do
echo $line
#关键字出现后退出日志打印
echo "$line" | grep "$2" >/dev/null 2>&1
if [ $? = 0 ];then
break
fi
#退出tail命令
ps -aux | grep "tail -n" | grep -v "grep" | awk '{print $2}' | while read line;
do
kill -9 $line
done
done
check_wait_log /home/mysql/mysqld.log "ready for connections"
网友评论