MacOS – Terminal: Is there a way to be notified of activity when tailing an error log

macossshtailterminal

I often ssh into a machine and tail -f it's php error log. My ideal situation would be to leave this terminal window open in the background, but when there's activity from the tail command, have the terminal window be activated and moved to front, or notify me in some way that an error has been written. This way I wouldn't have to always keep space on my desktop reserved.

Does this make sense?

Best Answer

Terminal's Dock icon starts bouncing if a tab that isn't active prints \a:

tail -f /var/log/system.log | sed $'s/$/\a/'

Or run sudo gem install terminal-notifier and do something like this:

tail -f /var/log/system.log | while IFS= read -r l; do echo "$l"; terminal-notifier -message "$l" > /dev/null; done