The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script to extract line from logfile garryt21@rediff Shell Programming and Scripting 25 10-08-2009 11:46 AM
Logfile rotation script. HardyV2 Shell Programming and Scripting 3 08-24-2009 10:51 AM
Attaching a logfile to the Script matt02 Shell Programming and Scripting 9 06-17-2009 09:19 PM
Script to manipulate logfile text rosspaddock Shell Programming and Scripting 11 12-02-2008 10:10 PM
perl script to filter logfile norsk hedensk Shell Programming and Scripting 4 08-30-2002 04:51 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 2 Weeks Ago
elmesy elmesy is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 11
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; 2 Weeks Ago at 09:15 AM.. Reason: Please use code tags!
  #2 (permalink)  
Old 2 Weeks Ago
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
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 (permalink)  
Old 2 Weeks Ago
elmesy elmesy is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 11
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; 2 Weeks Ago at 09:15 AM.. Reason: Please indent your code and use code tags!
  #4 (permalink)  
Old 2 Weeks Ago
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
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 .
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0