The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Emergency UNIX and Linux Support !! Help Me!!
.
grep unix.com with google



Emergency UNIX and Linux Support !! Help Me!! Post your urgent questions here for highest visibility. Posting a new thread to this forum requires Bits. We monitor this forum to help people with emergencies, but we do not guarantee response time or answers. This forum is "best effort" only. Members who reply to posts here receive a bonus of 1000 Bits per reply.

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #8 (permalink)  
Old 11-26-2009
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,146
tail -f EssbaseLog.txt
will run forever and will present lines as they are added to the file. Thus your script will run forever too. You run your script once and let it find errors as they occur.

You didn't use --follow=log-file but you may need it. Post the output from:
uname -a
so folks know what version of unix you have.
  #9 (permalink)  
Old 11-27-2009
chakrapani's Avatar
Registered User
 

Join Date: Sep 2009
Location: Asia
Posts: 87
Post


Code:
ReadLines=0
while [ true ]
do
TMPVAR=$(date +%s)
Totallines=$(wc -l /var/log/YOU.log )
Totallines=$((Totallines-ReadLines))
tail -n $Totallines /var/log/YOU.log | grep -A 50 'PATTERN' > /tmp/$TMPVAR.tmpfile
if grep 'username' /tmp/$TMPVAR.tmpfile ;
 then
   mail -s failure xxxxx@yyy.com < /tmp/$TMPVAR.tmpfile
fi
rm -rf /tmp/$TMPVAR.tmpfile
sleep 900
done

Some concept .. You need to just check with syntax to suit your system.

Basically what I am trying
While [ true ] ---> infinate loop
TMPVAR ... just to create tmp file...
Checking number of lines now and subtracting from what we have previously read. So that we dont want to send error which we have seen already ..
Tail -n ... read only last lines ... what we have not read from previous run .. And check patten and get lines matching above matching pattern.
Then again grep in the 50 lines from PATTERN which are in tmp file .. to see if username is available or not ..

if Available then mail .. else ... Nothing ..
Cleanup: remove all tmp file etc .. and sleep for 900 sec 15 mins ..

Better place to put this check is in cron:

Incase you decide to put in cron removing while do ... then push this number to some tmp file .. Like records read and etc ..
Also make note of more details in the same tmp where number of records are saved.. details like log file creation date etc to reset ReadLines variables incase the log gets rotated .. truncated etc ...


When you change PATTERN and username for your system .. Please add proper escape character wherever applicable
  #10 (permalink)  
Old 12-01-2009
Registered User
 

Join Date: Jul 2005
Posts: 108
1. Use crontab to run every fifteen minutes, key "man crontab" in shell.

2. This script may work <script.sh <your text to grep>:

#!/usr/bin/ksh

thelog="/your/local/logpath"
user=$1
lines="50"

run () {

num1=$(cat -n $thelog |grep $1 |awk '{print $1}' |head -1)
num2=$(expr $num1 - $lines)


if [ $num1 -gt 50 ]
then
results=$(cat -n $thelog |sed -n "$num2,${num1}p")

else
results=$(cat -n $thelog |sed -n '1,50p')

fi
echo "$results" |mailx -s "blabla" yourmailbox@nospamplease.com
}


run $user;
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Finding a word at specific location in a string swapnil.nawale Shell Programming and Scripting 1 09-14-2009 09:49 AM
Word count of lines ending with certain word warlock129 Shell Programming and Scripting 8 08-30-2009 04:37 AM
finding the number of occurence of a word in a line priyanka3006 Shell Programming and Scripting 9 06-18-2009 08:55 AM
need help with finding a word in file's contents manmeet Shell Programming and Scripting 6 10-01-2008 03:21 PM
Finding a word in a file smr_rashmy Shell Programming and Scripting 10 02-13-2008 02:02 AM



All times are GMT -4. The time now is 02:20 PM.


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