Logfile monitor script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Logfile monitor script
# 1  
Old 11-04-2009
Logfile monitor script

Hi,

I'm trying to write a logfile monitor script that reads the logfile and then emails out once there is an error with SQL in. Here is my attempt below which does not work. I'm not much of a scripter as you can probably see but some pointers in the right direction would be much appreciated.


Code:
DATE=`date`
DATE1="`date +%b` `date +%e` `date +%H`:`date +%M`"
HOST=`hostname`
LOG=/var/adm/sqllog
ERRORLOG=/home/sql/sqlerrlog
 
tail -f $LOG |
while true
do
  sleep 10
  read line
  echo "$line" | grep "$DATE1" | grep SQL > $ERRORLOG
done
 
if test -s $ERRORLOG; then
  mail -s "SQL errors in $LOG on $HOST $DATE" "me@host.com" < $ERRORLOG
fi


Last edited by Franklin52; 11-04-2009 at 09:15 AM.. Reason: Please use code tags!
# 2  
Old 11-04-2009
You can try something like this , if you want to check for errors :

Code:
DATE=`date`
DATE1="`date +%b` `date +%e` `date +%H`:`date +%M`"
HOST=`hostname`
LOG=/var/adm/sqllog
ERRORLOG=/home/sql/sqlerrlog
 
while true
do
tail -100 $ERRORLOG | grep  "ORA"  > /dev/null
if [ $? -eq 0 ];then
mail -s "SQL errors in $LOG on $HOST $DATE" "me@host.com" 
exit
fi
done

# 3  
Old 11-04-2009
Cheers for the reply, what i'm looking for is to make sure the the alert i'm sending an email for has just happend which is why I wanted to try use the $DATE1 = Nov 4 11:29 which is the same format as in the logfile. But If I try it doesn't work. Is it possible to grep twice from the output of a tail and direct it to /dev/null?

Code:
DATE=`date`
DATE1="`date +%b` `date +%e` `date +%H`:`date +%M`"
HOST=`hostname`
LOG=/var/adm/sqllog
ERRORLOG=/home/sql/sqlerrlog
 
while true
do
  tail -100 $LOG | grep "$DATE1" | grep "SQL" > /dev/null
if [ $? -eq 0 ];then
  mail -s "SQL errors in $LOG on $HOST $DATE" "me@host.com" 
  exit
fi
done


Last edited by Franklin52; 11-04-2009 at 09:15 AM.. Reason: Please indent your code and use code tags!
# 4  
Old 11-04-2009
Is it the code you posted not working ?..

check whether you have the data that matches the criteria "SQL" and

"$DATE" in the "sqlerrlog" file or not .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Logfile monitoring with logfile replacement

Bonjour, I've wrote a script to monitor a logfile in realtime. It is working almost perfeclty except for two things. The script use the following technique : tail -fn0 $logfile | \ while read line ; do ... some stuff done First one, I'd like a way to end the monitoring script if a... (3 Replies)
Discussion started by: Warluck
3 Replies

2. UNIX for Dummies Questions & Answers

Shell script to email logfile

Hi, I am trying to write a shell script to send a log file of a query run in oracle.Pls help me I am very new to shell scripting. echo " Checking Activity Spec " sqlplus / as sysdba <<END_SQL @activity_spec_metadata.sql quit;>>logfile END_SQL mailx -s "Checking Activity Spec schedule... (1 Reply)
Discussion started by: Rossdba
1 Replies

3. Shell Programming and Scripting

generate logfile in a shell script

Unix Gurus, I have a shell script which has few "echo" statements. I am trying to create a logfile where all the outputs of the echo statement sare stored. I will have to add this as the final step in the existing script so that everytime the script runs, a logfile is generated with all the... (1 Reply)
Discussion started by: shankar1dada
1 Replies

4. Shell Programming and Scripting

Script for Logfile Inserting into the Database

Here's the problem. I have a shell script running for every one minute as cronjob that outputs to a log file. I want to be able to take the data from the log file and insert it into a mysql database. The script needs to run at a set period of time and remove the log file data once the insert is... (7 Replies)
Discussion started by: kgrvamsi
7 Replies

5. Shell Programming and Scripting

Script to monitor errors in logfile

Hi, I would like to implements monitoring tool which looks at the logfile and sends me an email with error messages from the logfile. The runtime errors are printed in logfile. The logfile also contains some warning and debugging messages. For errors, the line will start with “Error”., the error... (1 Reply)
Discussion started by: LinuxLearner
1 Replies

6. Shell Programming and Scripting

Script to extract line from logfile

Hi , Can someone help me,I am not well versed with scripting,it is very urjent. Need a script in perl or shell for the following task. The logfile contains several entries of which one particular string to be searched and that complete line has to be removed and copied to another file to... (25 Replies)
Discussion started by: garryt21@rediff
25 Replies

7. Shell Programming and Scripting

Logfile rotation script.

I'm trying to find or create a Perl script that: Checks for and creates these files: notes notes.1 notes.2 notes.3 notes.4 The first represents the current log file and the others are older versions. Each time the script runs it would check for the existence of notes.3 and, if it exists,... (3 Replies)
Discussion started by: HardyV2
3 Replies

8. Shell Programming and Scripting

Attaching a logfile to the Script

Hello guys. I've recently written a basic utilities script just for home use. and i want to attach a logfile to it that will record all the commands that where executed in that script. Then just so i can add the d%b%y% and make each logfile unique and i can look back in each logfile to see what i... (9 Replies)
Discussion started by: matt02
9 Replies

9. Shell Programming and Scripting

Script to manipulate logfile text

Hi guys, I was wandering if a Shell guru could give me some advice on tackling a problem. I have used a mixture of grep, cut and awk to get data from a log file in the following format: 14/11/08 10:39: Checking currenly : Enabled 14/11/08 10:39: Records allocated : 221... (11 Replies)
Discussion started by: rosspaddock
11 Replies

10. Shell Programming and Scripting

perl script to filter logfile

i was wondering if anyone can help me, how could i write in perl a a script that would look through a log file and print onscreen the contents of the log file excluding lines that contain '192.168.1.' and entries that contain directory paths that arent in the directory /usr/local/httpd/htdocs/ i... (4 Replies)
Discussion started by: norsk hedensk
4 Replies
Login or Register to Ask a Question