All pastes #718594 Raw Edit

Unnamed

public text v1 · immutable
#718594 ·published 2007-09-28 15:23 UTC
rendered paste body
#!/bin/bash

tail -0f /var/log/messages | grep --line-buffered 'FLAG' | \
while :
do
        read junk
        if [ $? -ne 0 ]
        then
                echo "End of log!"
                exit
        fi
        echo "Got the message: $junk"
#       echo "Got the message" | mail -s 'email alert' whomever@wherever.com
done

---->8-----

This is a modest example of watching for a syslog message under linux and triggering an event.  In this case we watch simply for the word "FLAG" to appear in the syslog and then we just output "We got the message: " followed by the full line of text.  There is a commented example of sending an email instead.    

You can run this script in one screen then do a "logger FLAG" in another screen to see it work.