Parse for errors shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parse for errors shell script
# 1  
Old 01-18-2005
Parse for errors shell script

All,

I have a shell script which parses the /var/adm/messages file for errors every 15 minutes as a cron job. The script runs at 01, 16, 31, and 46 minutes every hour. The problem is if the error is encountered any time during the beginning of hour I can get paged three times. I would like to find a way to take the current time and subtract the previous time interval (for example 15 minutes) to read only the messages from this time. This way I would only get paged once. Any suggestions to improve the shell script are appreciated.

Thanks,

Mike

Here is the shell script:

#!/bin/sh
#
# Script to read the /var/adm/messages file for errors.
#
# Environment variables
#
LOGFILE=/sysadmin/varmessages.log
OLDLOGFILE=/sysadmin/varmessages.old.log
MESSAGES=/var/adm/messages
MESSAGEALERT=/sysadmin/varmessagealart.txt

CURMONTH=`date +%m`
CURDAY=`date +%d`
CURYEAR=`date +%Y`

# Convert numeric month to character for today's month.
case $CURMONTH in
1|01) CURMONTH=Jan;;
2|02) CURMONTH=Feb;;
3|03) CURMONTH=Mar;;
4|04) CURMONTH=Apr;;
5|05) CURMONTH=May;;
6|06) CURMONTH=Jun;;
7|07) CURMONTH=Jul;;
8|08) CURMONTH=Aug;;
9|09) CURMONTH=Sep;;
10) CURMONTH=Oct;;
11) CURMONTH=Nov;;
12) CURMONTH=Dec;;
esac

# Remove leading zeros from today's day.
case $CURDAY in
01) CURDAY=1;;
02) CURDAY=2;;
03) CURDAY=3;;
04) CURDAY=4;;
05) CURDAY=5;;
06) CURDAY=6;;
07) CURDAY=7;;
08) CURDAY=8;;
09) CURDAY=9;;
esac

# Get current hour for today.
#
THOUR=`date +%T | awk -F: '{ print $1 }'`

# If the hour is less than 10, add a leading zero to hour.
HOUR=$THOUR
case $i in
0) HOUR=00;;
1) HOUR=01;;
2) HOUR=02;;
3) HOUR=03;;
4) HOUR=04;;
5) HOUR=05;;
6) HOUR=06;;
7) HOUR=07;;
8) HOUR=08;;
9) HOUR=09;;
esac

# Remove log file if the file exists
if [ -f $LOGFILE ] ; then
rm $LOGFILE
fi

# Remove old log file if the file exists
if [ -f $OLDLOGFILE ] ; then
rm $OLDLOGFILE
fi

# Loop through lines in the MESSAGEALERT text file and grep for
# line in the MESSAGES text file. If the line is found at least
# once and it has not been reported, then place in log file.
while LINE="`line`"
do
ALERT=`grep -c "$LINE" $MESSAGES`

# grep for alerts in the current hour
if [ $CURDAY -lt 10 ] ; then
cat $MESSAGES | grep "$CURMONTH $CURDAY $HOUR" | grep "$LINE" >> $LOGFILE
else
cat $MESSAGES | grep "$CURMONTH $CURDAY $HOUR" | grep "$LINE" >> $LOGFILE
fi

done < $MESSAGEALERT

# Loop through lines in the MESSAGEALERT text file and grep for
# line in the MESSAGES text file. If the line is found at least
# once and it has not been reported, then place in log file.
while LINE="`line`"
do
ALERT=`grep -c "$LINE" $LOGFILE`

# grep for alerts in the current hour and send page from /etc/aliases alias
if [ $ALERT -ge 1 ] ; then
echo "$LINE" >> $OLDLOGFILE
echo "$LINE" | mailx -s "`uname -n` system messages alert" pager
fi

done < $MESSAGEALERT

exit 0

The /sysadmin/varmessagealart.txt has the following text to parse for:
Media Error
Memory Error
Hardware Error
SCSI bus reset
# 2  
Old 01-18-2005
Can we run this script by sleeping for 15 minutes and check the log
instead of running as cron job.

If you run it as script and maintain a flag variable.If page is sent set the flag as "SENT". In the next hout reset the flag to BLANK.
# 3  
Old 04-02-2009
Command we tried using to grep ERROR from lastest 1 log files from 5 logs files available in that particular directory is:
grep ERROR 'ls -ltr | tail -1'

but this command is not working.. for me its saying.. cannot open DistributeImageFilesToTarget_10_dataLocations_PhillipinesDataLocations.xml.log

if i give ls -lrt for all the files in that diretory

-------r-- 1 egdevbb intdev 5022 Apr 2 05:13 DistributeDataFilesToTarget_4_dataLocations_ChinaDataLocations.xml.log
-------r-- 1 egdevbb intdev 1672 Apr 2 05:14 DistributeImageFilesToTarget_14_dataLocations_WHQDataLocations.xml.log
-------r-- 1 egdevbb intdev 7480 Apr 2 05:15 DistributeImageFilesToTarget_60_dataLocations_IndonesiaDataLocations.xml.log
-------r-- 1 egdevbb intdev 2113 Apr 2 05:34 DistributeImageFilesToTarget_8_dataLocations_MalaysiaDataLocations.xml.log
-------r-- 1 egdevbb intdev 2107 Apr 2 05:39 DistributeImageFilesToTarget_10_dataLocations_PhillipinesDataLocations.xml.log
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Errors in if condition validations-Shell Script

Hello All, i am facing difficulty in validating the values, kindly help me in resolving the issue. Thanks a lot in advance. -Chandra Script:Test.sh #! /bin/sh # *************************************************************************** # Function to display help function usage()... (1 Reply)
Discussion started by: duddukuri
1 Replies

2. Shell Programming and Scripting

How to turn off ora errors in shell script?

I have a shell script which select total count from a table and use its value in a if condition like below connect_string="username/password@tnsname" tot=`sqlplus -s $connect_string << EOF set echo off set feedback off set head off select count(*) from test_table; EOF ` if then echo... (2 Replies)
Discussion started by: vel4ever
2 Replies

3. Shell Programming and Scripting

shell script for conky getting errors....

So I have a script that does a greater than or less than with a variable. My problem is that when I checked the script from the command line I was getting this error.. I am not really familiar with shell scripting. I am trying to get this script to work with conky so that it will do the... (8 Replies)
Discussion started by: krisdeniseriley
8 Replies

4. Emergency UNIX and Linux Support

Seek help on shell script syntax errors

I want to delete archivelog files that has been archived and applied from primary database to standby database. This piece of script is working in Linux server. However, I copy it to Unix server with tiny modification. It won't work and generate the error message. I have checked code carefullt... (8 Replies)
Discussion started by: duke0001
8 Replies

5. Shell Programming and Scripting

Capture makefile errors in shell script

Hi, I have a bash script which calls a few "make". I would like to know whether the makefile failed with any errors. How do I do that in the script? Thanks, S (2 Replies)
Discussion started by: suryaemlinux
2 Replies

6. Shell Programming and Scripting

Bash Shell Script to parse file

Raw Results: results|192.168.2|192.168.2.1|general/udp|10287|Security Note|For your information, here is the traceroute from 192.168.2.24 to 192.168.2.1 : \n192.168.2.24\n192.168.2.1\n\n results|192.168.2|192.168.2.1|ssh (22/tcp)|22964|Security Note|An SSH server is running on this port.\n... (2 Replies)
Discussion started by: jroberson
2 Replies

7. Shell Programming and Scripting

Bad substitution errors in shell script

Hello, I was hoping for a second pair of eyes or a little bit of help figuring out what my error is in a script. I did some searching in the forums and didn't find anything so please forgive me if it a similar problem has been discussed before. My script accepts normal user arguments; however,... (2 Replies)
Discussion started by: Jackinthemox
2 Replies

8. Shell Programming and Scripting

Help with shell script errors

hey watsup guys i am new in the shell script world. so i need help fom you guys, i have written these two codes and they both give the same errors( expr : syntax error). Code 1 : #! /bin/sh # count1 appends an increment to a file 200 times # note that a file called numbers must be... (5 Replies)
Discussion started by: surubi_abada
5 Replies

9. UNIX for Advanced & Expert Users

shell script to parse html file

hi all, i have a html file something similar to this. <tr class="evenrow"> <td class="data">added</td><td class="data">xyz@abc.com</td> <td class="data">filename.sql</td><td class="modifications-data">08/25/2009 07:58:40</td><td class="data">Added TK prof script</td> </tr> <tr... (1 Reply)
Discussion started by: sais
1 Replies

10. Shell Programming and Scripting

parse data between parenthesis using shell script

Hi I am using shell script and i need to parse the data between parenthesis.How do i do it using shell script. Ex: section(name). I want to extract name from the above string using shell script. (4 Replies)
Discussion started by: julie_s
4 Replies
Login or Register to Ask a Question