screen causes "tail -F | grep" to echo unmatched lines
When you launch the pipe such way:
screen -S "wordwatch" tail -F server.log | grep --line-buffered "word" | tee -a wordwatch.log
then only tail -F server.log
is launched within screen
and all the rest is connected to the screen
, not the tail
.
Therefore you should invoke your bash script that works already:
screen -S "wordwatch" myworkingscript.sh
The other approach is to launch the shell explicitly and pass all the line to it:
screen -S "wordwatch" bash -c 'tail -F server.log | grep --line-buffered "word" | tee -a wordwatch.log'
Also the other good way to watch logs with screen - is the special config:
#### logger.screenrc
sessionname logger
hardstatus alwaysignore
split
split
screen -t "Log One" 1 sh -c 'tail -F /a/b/c | egrep "xxxx" | tee -a '
focus
screen -t "Log Two" 2 /home/somescript.sh
focus
screen -t "Messages" 3 /home/otherscript.sh
focus
####
screen
should be invoked like that:
# screen -c /home/logger.screenrc
To exit just press <CTRL-A><CTRL-\>
and confirm.