tail监控日志关键字退出

2022-04-03  本文已影响0人  醉眼看人间_个个都温柔
#!/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"
上一篇下一篇

猜你喜欢

热点阅读