The UNIX and Linux Forums  

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
Writing a shell in Python sadistik_exec High Level Programming 1 08-15-2008 03:22 AM
seeking help with shell script Niadh Shell Programming and Scripting 4 10-17-2007 10:17 AM
Difference between writing Unix Shell script and AIX Shell Scripts haroonec AIX 0 04-12-2006 03:27 AM
Need help for writing shell script deepa20 Shell Programming and Scripting 3 02-01-2006 01:23 PM
Is writing shell scripts different than... brentdeback Shell Programming and Scripting 1 10-28-2005 10:20 PM

Closed Thread
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 01-19-2009
anakiar anakiar is offline
Registered User
  
 

Join Date: Jul 2008
Location: Cyberjaya, Malaysia
Posts: 12
Unhappy Seeking for help in writing shell

Hi All,

I got a problem and stuck to filter a log file, called it as "sample.log". This "sample.log" file is being generated by "script A". The "sample.log" look like below:


Code:
:FORMATDATE_FORMATTIME:CmdArg->:SomeDoce:SomeFormatDocument:
:FORMATDATE_FORMATTIME:imprtcp succeeded.
:FORMATDATE_FORMATTIME:imprttyp completed.
:FORMATDATE_FORMATTIME:fdcode2 failed
::
::...........................
:FORMATDATE_FORMATTIME:CmdArg->:SomeDoce:SomeFormatDocument:
:FORMATDATE_FORMATTIME:imprtcp succeeded.
:FORMATDATE_FORMATTIME:imprttyp completed.
:FORMATDATE_FORMATTIME:DocCode = yadayada(00)
:FORMATDATE_FORMATTIME:Document type is yada.
:FORMATDATE_FORMATTIME:Document not paginated or not text.
:FORMATDATE_FORMATTIME:yada yada succeeded.
:FORMATDATE_FORMATTIME:yada yada succeeded, size=1248.
:FORMATDATE_FORMATTIME:nimport succeeded.

What i try to do is,Since the "sample.log" is actively growing up. i need to

1) Grep the the value failed and also all the required data. i should get like below:-

Code:
:FORMATDATE_FORMATTIME:CmdArg->:SomeDoce:SomeFormatDocument:
:FORMATDATE_FORMATTIME:imprtcp succeeded.
:FORMATDATE_FORMATTIME:imprttyp completed.
 :FORMATDATE_FORMATTIME:fdcode2 failed

2) and email it to the me as an alert.

P/S this script will run in cron to actively monitor the "failed" data.
May be somebody cay help me on figure it out how can i do this.

Currently what i have is:

1) tail -f sample.log | grep failed >> samplelog.failed
## but i stuck at here because tail -f cannot output to other files, i tried but failed, no output has been generate.

2)
test=$(cat samplelog.failed | cut -d: -f-2)
cat sample.log | grep $test: | /usr/bin/mailx -s "Subject" to@somebody


Thanks for your helping in here.
  #2 (permalink)  
Old 01-19-2009
bclaus2 bclaus2 is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 1
Try this.

head test.txt | egrep "failed" | while read line
do
print - $line | read word1 word2 word3
if [[ $word2 = "failed" ]]
then
email command
fi
done
Closed Thread

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 06:21 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