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

前端 未结 3 1792
眼角桃花
眼角桃花 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条回答
  •  心在旅途
    2021-01-07 00:21

    > $var doesn't do what you think it does.
    It redirects the output of the preceding command to a file with name of what $var contains.
    To capture the output of a command and put it into a variable, use variableName="$(...)".

    var="$(tail -f /var/log/named.log | grep $1)"
    

提交回复
热议问题