donderdag 28 februari 2013

watching a logfile and doing stuff

I needed to watcha logfile and trigger an action if a specific line appeared in the logs

    #tail the file you want to watch
    tail -fn0 /var/log/logfile | while read line ; do
            echo "$line" | grep 'line to react to' | grep -v 'things to block the reaction' 
            if [ $? = 0 ]
                    # do things
                    echo "just saw $line"
                    mpg123 triomph.mp3

save this as
make it exectuable (chmod +x 
and let it run in the background ./ & 

Geen opmerkingen: