grep only last occurred error in error.log,


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep only last occurred error in error.log,
# 1  
Old 07-14-2010
grep only last occurred error in error.log,

hi folk i need your help to find one logic....

i have error log same as any other error logs which get populated by no of events and errors...

but i need to grep the last occured errors.. which cant be duplicate.

here is my script.
========================
Code:
#!/usr/bin/ksh
grep -i "STOP" $BATE/err.log > /tmp/bbs.lst   --capture error into tmp 
checkFile=/tmp/bbs.lst               
if [ -e $checkFile ]; then        ----if file is not empty 
mailx -s  'errors' XYZ@gmail.com < $checkFile
else
echo "dont worry process is fine" > /tmp/bbr.log   ---throwing into dump 
fi
rm -rf /tmp/bbs.lst       -----removing tmp

====================================

now problem is if i wake up this script every 2 min ,,
i need to check last 2 min errors which is in $BATE/err.log and sending to
/tmp/bbs.lst

suppose if it capture one error at 9:30 pm
after sometime if the script is wakup at 9:32 pm
and find again that same error which occured at 9:30 pm

so i want to capture the errors but dont want to duplicate it..

my err.log format will be something like this one

====================================================
Code:
2010-07-09 10:11:07  bb ERROR  250   XX.rm:  PROCESS STOP
2010-07-09 10:12:48  bb ERROR  250   XX.rm:  PROCESS STOP
2010-07-09 12:38:33  bb ERROR  250   XX.rm:  PROCESS STOP
2010-07-09 17:05:02  bb ERROR  250   XX.rm:  PROCESS STOP

can you guys help me in this ???

Last edited by vgersh99; 07-14-2010 at 12:21 PM.. Reason: code tags, please!
# 2  
Old 07-14-2010
If you're working with Linux, try:
Code:
tac err.log | grep -m 1 ERROR



---------- Post updated at 17:30 ---------- Previous update was at 17:28 ----------

I'm not sure if this is what you wanted Smilie
# 3  
Old 07-14-2010
No my friend i m just using solaris 9 ,,,,,
# 4  
Old 07-15-2010
Hi Tapia, i have done some changes in the script. have not run it, just have given scrached on it. You can made some changes and compile it and it should work

let me explan you the logic. put a dummy time stamp in a temp file as
TIMESTAMPF=/tmp/timestamperr.log //put a dummt time like 00:00:00
next search the erro string from your file, get the last line and the time stamp from it and compare with the time stamp in /tmp/timestamperr.log.
if it matches, then there is no error and if it does not then there is error has occured recently.

I hope you got what i am trying to say.

#!/usr/bin/ksh
TIMESTAMPF=/tmp/timestamperr.log //put a dummt time like 00:00:00
grep -i "STOP" $BATE/err.log > /tmp/bbs.lst --capture error into tmp
checkFile=/tmp/bbs.lst
if [ -e $checkFile ]; then ----if file is not empty
ctimeerr=`tail -1 $checkFile | awk '{ print $2 }'` //get the time stamp for the last occured err string
ptimeerr=`head -1 $TIMESTAMPF` //contain the time stamp , dummy one, once only
if [ $timeerr = $ptimeerr ]
then
echo "dont worry process is fine, no errors occured" > /tmp/bbr.log ---throwing into dump
else
tail -1 $checkFile | awk '{ print $2 }' > $TIMESTAMPF
mailx -s 'errors' XYZ@gmail.com
fi
fi
rm -rf /tmp/bbs.lst -----removing tmp
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print Error in Console and both Error & Output in Log file - UNIX

I am writing a shell script with 2 run time arguments. During the execution if i got any error, then it needs to redirected to a error file and in console. Also both error and output to be redirected to a log file. But i am facing the below error. #! /bin/sh errExit () { errMsg=`cat... (1 Reply)
Discussion started by: sarathy_a35
1 Replies

2. Shell Programming and Scripting

Error occurred during initialization of VM

Hi , I was invoking a sh file using the nohup command. But while invoking, I received a below error. Error occurred during initialization of VM Unable to load native library: /u01/libjava.so: cannot open shared object file: No such file or directory . Could you please help out. Regards,... (2 Replies)
Discussion started by: Kamal1108
2 Replies

3. AIX

0511-193 An error occurred

Hi, When i am trying to read data from tape cassette its giving below error: tar tvf /dev/rmt0 "tar: 0511-193 An error occurred while reading from the media. A system call received a parameter that is not valid." OS: - AIX 6.1 Tape Library : - IBM TS3100 Tape Cassette : - Ultrium LTO... (1 Reply)
Discussion started by: arunmistry
1 Replies

4. Solaris

Error occurred while making the net-snmp 5.4.4 on Solaris 5.10 version.

Hi all, Error occurred while making the net-snmp-5.4.4 on Solaris 5.10 version. Environment - Solaris 5.10-x86 - Net-SNMP-5.4.4.tar.gz - Path (/etc/profile) PATH=/usr/local/bin:$PATH export PATH LD_LIBRARY_PATHUSR=/usr/ccs/bin: export LD_LIBRARY_PATH Error01 - summary ***... (3 Replies)
Discussion started by: ziosnim
3 Replies

5. Red Hat

KusuDB: Operational Error occurred when connecting to the DB

I have RHEL5.3 that is with the Platform Cluster Manger PCM installation. on master node. Unfortunately some files were deleted from the /var directory and then the postgresql service couldn't start. I have deleted, rm -rf /var/lib/pgsql/data and started the service again now the service is running... (1 Reply)
Discussion started by: ahsanpmd
1 Replies

6. Shell Programming and Scripting

Log file is not getting created & unable to grep error from it

Hi All, Below is my code,what I am trying to do is redirecting output of ftp to a log file & then greping the errors but here I am unable to grep "Permission denied" error only & also the corresponding log file is also not getting created. #!/bin/sh . cfg USER='abc' PASSWD='abc123' ... (4 Replies)
Discussion started by: ss_ss
4 Replies

7. Shell Programming and Scripting

sort: 0653-657 A write error occurred while sorting.

Hi I am trying to sort a file of 88075743B size. I am doing some processing on the file and after the processing is done; I get 2 files temp1 and temp2. I need to combine both these files as one and this final file should be sorted on fields 1 and 2. Space is the delimiter between fields. Record... (2 Replies)
Discussion started by: diksha2207
2 Replies

8. Red Hat

rhn_register A socket error occurred

All, I'm getting the following error while I try to register the server to connect the redhat network for the updates. rhn_register updateLoginInfo() login info rhn_register A socket error occurred: (111, 'Connection refused'), attempt #1 rhn_register A socket error occurred: (111,... (6 Replies)
Discussion started by: s_linux
6 Replies
Login or Register to Ask a Question