LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Actively Monitoring Log File (https://www.linuxquestions.org/questions/linux-newbie-8/actively-monitoring-log-file-881900/)

Fracker 05-21-2011 12:35 AM

Actively Monitoring Log File
 
I have an application which generate logs like this

Code:

                                                                2011-05-17 13:21:27 - Msg 2402
File loading terminated.

File information: 3 records in input file found
                  3 records processed
                  0 records skipped
Load statistics:  3 messages loaded correctly
                  0 messages ignored
                  0 messages with errors
Details:
  Destination              OK    ignored    errors    correct  incorrect  not sel.      other
  ---------------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
  house Server (def          3          0          0          0          2          1          0

                                                              2011-05-17 13:21:27 - Msg 2410
Archiving information: File /path/to/xxx.txt
was archived as /path/to/xxx.txt.

now i want to moniter this "house Server (def" and send alert based on 3 0 0 0 2 1 0

say if [ $5 -gt 0 || $6 -gt 0 ]; then
<send email>

Fracker 05-21-2011 10:35 AM

no one knows? :/

zunder1990 05-21-2011 11:43 AM

Take a look at some code that I wrote. this would give you the if then part.
Code:

if [ $? -eq 0 ]; then  # check the exit code
        echo "$ip is up" >> /root/Desktop/iplog #write  the ip of the hosts that are up
       
    else
        echo "$ip is down" # will show on the screen the ips that are not up
        logger -p auth.notice "$ip is down" # will write the down host to syslog
        echo "$ip is down" | mail -v -s alert user@anydomain.com > /dev/null 2> /dev/null #will send mail users about host down
    fi


Fracker 05-23-2011 12:23 AM

Code:

# tail -f logfile | grep "house server (def" | awk '{
print $1
print $2
print $3
print $4
print $5
print $6
print $7
print $8
}'

what is problem here?

chrism01 05-23-2011 01:02 AM

I'd try more like
Code:

tail -f logfile | grep "house Server" |awk '{print $5 $6}'
noting that you said you wanted fields 5 & 6 earlier. Also, tricky to tell without seeing the err msg/output you got, but I'd expect that the '(' caused an issue as it's a 'Special Char' in shell scripting.
Also, *nix is case sensitive, so 'server' != 'Server'.
HTH

Fracker 05-23-2011 05:37 AM

nope still not working..

ps: i was just using it for testing purpose as if i can get the argument, then i can manipulate them which is why i used "server" instead of "Server"

syg00 05-23-2011 06:04 AM

Prove to yourself you have a record to print ...


All times are GMT -5. The time now is 10:20 PM.