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)

1
  • 1
    you can do that using python script like here
    – Mero
    Feb 15, 2017 at 15:28

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.