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
> $vardoesn't do what you think it does.It redirects the output of the preceding command to a file with name of what
$varcontains.To capture the output of a command and put it into a variable, use
variableName="$(...)".