![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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! |
|
||||
|
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 |
|
||||
|
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! |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|