I would like to monitor my /var/log/syslog continuously. However while monitoring, I would like to avoid certain pattern(s) while monitoring. I am interested only in the last 15 (for example) lines.
For the usual monitoring I use the command:
watch -n 1 tail -n 15 /var/log/syslog
Whereas, what I actually would like to have is something like:
watch -n 1 tail -n 15 /var/log/syslog | grep -v -E 'pattern1|pattern2'
Being more specific with my requirement:
I would like to continuously monitor entries in the syslog, avoiding certain pattern(s). The screen should get refreshed every fixed period (say 1s or 2s).
Following are more (failed) attempts:
watch cat /var/log/syslog | grep -v -E 'pattern1|pattern2'
A (partially) successful attempt:
while true;
do
clear;
cat /var/log/syslog | grep -v -E 'pattern1|pattern2' | tail -15;
sleep 1;
echo '\"CTRL-C\" to close';
done
However the smoothness of watch is lost here.
Summary
So the question is is there any way to combine watch, tail and grep?
I am using bash 4.4.7 on 17.04.
tail -f? That works withgrep... – Zanna Jun 27 '17 at 14:21watchclubbed withtail. – Mike V.D.C. Jun 27 '17 at 14:30tail -fwill keep on priducing the output. The first line on the screen (till the screen fills up and starts scrolling) will always be the same. I would only lastnlines displayed. In some sense, forced scrolling. – Mike V.D.C. Jun 27 '17 at 14:51nlines fit and then usetail -f. Then you will achieve what you want! Adjusting size is (trivially) possible for agnome-terminal. But its also possible forscreen/tmuxbased terminals. – user5325 Jun 27 '17 at 14:57glogg. It can monitor syslog, or any log file, and give you control over search strings. – heynnema Jun 27 '17 at 15:40watch -n 1 'tail -n 15 /var/log/syslog | grep -v -E "pattern1|pattern2"'(the quoting is significant; you want the whole pipeline to run in thewatchI think) – steeldriver Jun 27 '17 at 16:13glogg. – Mike V.D.C. Jun 28 '17 at 04:32