Using tail -f on a log file with grep in bash script

前端 未结 3 1812
眼角桃花
眼角桃花 2021-01-06 23:53

I\'d like to create a script that greps for a specific string in a log file that is being written to. I\'d like to take the first result and put that into a variable for lat

3条回答
  •  -上瘾入骨i
    2021-01-07 00:10

    Thank you all for the input. You helped figure out a better way to do it, using while and tail without -f

    werd=$1
    var=""
    while [ "${var}" == "" ]
    do
    var=$(tail -1 /var/log/named.log | grep "${werd}");
    done
    echo "${var}";
    

    This just reads the last line in the file. Since the file is being written to, the last line changes which is the result I was looking for.

提交回复
热议问题