LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Events on Log analyse (https://www.linuxquestions.org/questions/programming-9/events-on-log-analyse-251632/)

dough29 11-05-2004 06:55 PM

Events on Log analyse
 
Hello ! I'm French so sorry if my English isn't the best.

I would like to have a shell script making events analysing my logs in /var/log/

For example, by running tail -f /var/log/apache/access.log - I would like, for each GET requests, to run a command like /usr/bin/beep to make simple.

Thank you in advance !!

mgatny 11-07-2004 01:00 PM

Save the follow shell script as beep.sh, then run:
chmod +x beep.sh

Then run:
tail -f /var/log/apache/access.log | beep.sh GET

The argument to beep.sh is the string you want to match on. So if you wanted to look for HEAD requests instead of GET, run it like this:
tail -f /var/log/apache/access.log | beep.sh HEAD

Or for a particular IP address:
tail -f /var/log/apache/access.log | beep.sh "192.168.0.123"

... You get the idea. Also, your English is quite good ;)

Code:

#!/bin/sh

while [ 1 ]; do
        read foo;
        echo $foo | grep "$1" > /dev/null 2>&1
        if [ $? -eq 0 ]; then
                /usr/bin/beep
        fi
done


dough29 11-07-2004 01:20 PM

Thanks a lot !

It works verry fine.


All times are GMT -5. The time now is 08:30 PM.