Online log monitoring script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Online log monitoring script
# 1  
Old 03-14-2012
Online log monitoring script

Code:
#!/bin/bash

tail /oracle/app/admin/ABC/bdump/alert_ABC.log >> tempoutput&


Error=`egrep 'error|warn|critical|fail|ORA-1683' tempoutput`

echo "$Error" |mailx -s "ABC Error "  ABCD@domain.lk

cat /dev/null > tempoutput

I wrote this script and put in to cronjob every 5 min.
so every 5 min i got the empty e-mail. That's not i wont.
i wont to if getting those "error|warn|critical|fail|ORA-1683" things , genarate the mail.( Execute this "mailx -s "ABC Error " ABCD@domain.lk" )

any one can help me...
Thanks.

Last edited by Franklin52; 03-14-2012 at 10:53 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 03-14-2012
Use the conditions in you schedule script. if it meet with the conditions sent email else exit...

Like this ...
Code:
if [ $? -eq 0 ]; then
 #errors mail
 #update logfile
exit 1;
fi


Last edited by Franklin52; 03-14-2012 at 10:53 AM.. Reason: Please use code tags for data and code samples, thank you
Mohammed Fareed
# 3  
Old 03-14-2012
Quote:
Originally Posted by hishanms
#!/bin/bash

tail /oracle/app/admin/ABC/bdump/alert_ABC.log >> tempoutput&


Error=`egrep 'error|warn|critical|fail|ORA-1683' tempoutput`

echo "$Error" |mailx -s "ABC Error " ABCD@domain.lk

cat /dev/null > tempoutput

I wrote this script and put in to cronjob every 5 min.
so every 5 min i got the empty e-mail. That's not i wont.
i wont to if getting those "error|warn|critical|fail|ORA-1683" things , genarate the mail.( Execute this "mailx -s "ABC Error " ABCD@domain.lk" )

any one can help me...
Thanks.
Try to fire mailx only when $Error is not null

Code:
if [[ -z $Error ]]
echo "$Error" |mailx -s "ABC Error" ABCD@domain.lk 
fi

# 4  
Old 03-15-2012
Quote:
Originally Posted by codemaniac
Try to fire mailx only when $Error is not null

Code:
if [[ -z $Error ]]
echo "$Error" |mailx -s "ABC Error" ABCD@domain.lk 
fi

I tried this and it's perfectly working.
Thanks everyone.

Code:
#!/bin/bash  
tail /oracle/app/admin/ABC/bdump/alert_ABC.log >> /tmp/tempoutput 
  
Error=`egrep 'error|warn|critical|fail|ORA-1683' /tmp/tempoutput ` 

echo $Error >/tmp/error 
count=`echo $Error|wc -w`

IP=`/usr/sbin/ifconfig ce0 | grep inet | awk '{print $2}'`

if [ $count -ne 0 ] 
then 
echo "$Error" |mailx -s "ABC Error -($IP) "  ABCD@domain.lk
fi 
 
> /tmp/tempoutput
> /tmp/error

[/QUOTE]

Last edited by hishanms; 03-15-2012 at 05:24 AM..
# 5  
Old 03-15-2012
Try this using named pipe.

Code:
NM=/tmp/nmpipe
LOG=input # your log
mkfifo $NM
tail -f -n 0 $LOG > $NM & TPID=$!
while true
do
egrep -q 'error|warn|critical|fail|ORA-1683' $NM
        if [ $? -eq 0 ] 
        then
        i=$(( i + 1 ))
        case $i in
                5) echo "$i errors detected, please check\n"
        ;;
                10) echo "$i error threshold reached, please check, restarting..."
                kill $TPID && i=0
                rm -f $NM
                sleep 5
                mkfifo $NM
                tail -f -n 0 $LOG > $NM & TPID=$!
        ;;
        esac
        fi
done

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script for continuously monitoring log file

Hi I have written below log monitoring script to egrep multiple words and redirect the output to a text file and its working fine but I want to add some more below given functionality to it, which is very advance and im not very good in it, so please help if you can :) I am egrepping all the... (1 Reply)
Discussion started by: scazed
1 Replies

2. UNIX for Beginners Questions & Answers

Monitoring script for Log file

Hi, Iam new to unix , plz help me to write below script. I need to write a script for Monitoring log file when any error occurs it has to send a mail to specified users and it should be always pick latest error not the existing one and the script should be able to send mail all errors (more... (1 Reply)
Discussion started by: vij05
1 Replies

3. Shell Programming and Scripting

Monitoring script for a log file

Hi, I need to get a script working to monitor a log file and throw an alert via mailx as soon as a particular error is encountered. I do not want repeatative email notifications of same error so simply cat logfile and grepping the error would not work. Here is what i planned but it seems... (2 Replies)
Discussion started by: roshan.171188
2 Replies

4. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

5. Shell Programming and Scripting

Log folder size monitoring script

Hi All, Can anyone refer to me a readymade script for the purpose of log folder size monitoring script. Example : I have a log folder of size 10 G, and as the logs keep accumulating the folder gets full and i have to manually zip/remove the files in order to keep the server running. Something... (1 Reply)
Discussion started by: findjai
1 Replies

6. Shell Programming and Scripting

help needed - log file monitoring script

hi Gurus, Need to pick your brains on this minor script project. I would like to continuously monitor a log file with sample log messages as below, and if PSOldGen percentage is either 99% or 100% for consecutively 10 times, alert someone. {Heap before gc invocations=46516: PSYoungGen ... (6 Replies)
Discussion started by: kenchen722
6 Replies

7. Shell Programming and Scripting

Online log

Hi, I have this situation: There is an online.log to which one app is continuously writing. This app is 24*7. This log will fill up our File system pretty quickly. Such that I need to take backups of that file for safekeeping without stopping the App. These backups I can move to another... (5 Replies)
Discussion started by: chaandana
5 Replies
Login or Register to Ask a Question