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 later use. This will be used though an SSH connection like so:
ssh '[email protected]' 'bash -s' < /usr/local/bin/checklog.sh string
The command in a regular terminal
tail -f /var/log/named.log | grep $1 > $var
echo "${var}"
When I try the above method, there's no output
Thank you all for the input. You helped figure out a better way to do it, using while and tail without -f
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.