4

I want to monitor a log file (omxd log file) in real time, and execute some commands when some sentences appear in the log.

I searched this site (and many other sites) and these are what I tried:

tail -f /var/log/omxlog | awk '/player_new/ { "echo hello" }'

or

stdbuf -o0 tail -F /var/log/omxlog | awk '/player_new/ { "echo hello" }'

But they don't work. Whenever I run these commands, it begins to wait, but although I'm sure the log file changes, it doesn't print hello; actually it doesn't do anything. Just waiting :D

Maybe the problem is that I'm accessing the RPi via SSH. I don't know.

So, what should I do!?

(System: Raspberry Pi. OS: Minibian)

Omid1989
  • 662
  • 2
  • 14
  • 29

1 Answers1

3

Try using the watch command. Click here for man page. Maybe something like:

watch tail /var/log/omxlog | awk '/player_new/ { "echo hello" }'

watch runs command (in your case tail) repeatedly and outputs to terminal. By adding pipe (|) the output is redirected to the awk command.

NonStandardModel
  • 286
  • 2
  • 12