1

Good Afternoon

I am attempting to run a tail -f on a log file (shown below), but when running this I do not receive any output. However when I replace tail -f with cat the command runs and returns the information I need. Why would there be a difference? and what can I do to remedy this? Help Please

tail -f /var/log/monitor | grep -i 'is down/| is up' | awk '{print $1, $2, $4}'


cat /var/log/monitor | grep -i 'is down/| is up' | awk '{print $1, $2, $4}'


March 4 20:18:18 

March 4 20:20:18

March 4 20:25:18
riteshtch
  • 8,629
  • 4
  • 25
  • 38
Keith
  • 27
  • 5
  • 1
    use `--line-buffered` with `grep` and `fflush()` with `awk`... or take a look at `unbuffer` (probably in the `expect` package) – Attie Mar 03 '18 at 18:06
  • so would it be...... tail -n /var/log/monitor | grep -i 'is down/| is up' | awk '{print $1, $2, $4}' – Keith Mar 03 '18 at 18:09
  • When attempting to do tail -n, I receive illegal offset – Keith Mar 03 '18 at 18:23
  • You know that `tail -f` will copy out what it finds in the given file but it never sends out and end-of-file to close out the pipe, right? It's intended to continue running and provide output line by line as the input file is updated. So if `grep` is buffering input, it's going to sit there and wait for the pipe to be closed before it will flush whatever it has left in its input buffer. If `/var/log/monitor` gets enough written to it, you'll probably start seeing output. For it to work otherwise, try Attie's suggestion. – lurker Mar 03 '18 at 18:28
  • @lurker how do i go about doing that... sorry I am new to the linux – Keith Mar 03 '18 at 18:30
  • so would it be... tail -f /var/log/monitor | grep --line-buffered -i 'is down/| is up' | awk '{print $1, $2, $4}' – Keith Mar 03 '18 at 18:31
  • https://stackoverflow.com/questions/7161821/how-to-grep-a-continuous-stream – VIPIN KUMAR Mar 03 '18 at 19:22

0 Answers0