Seeking for help in writing shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Seeking for help in writing shell
# 1  
Old 01-19-2009
Data 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  
Old 01-19-2009
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Seeking assistance in Shell script

#!/bin/bash >error_log for s in `cat s.txt` do uptime $s >>error_log echo $s >>error_log done The above code produce output with server name and its uptime in 2 different lines .My requirement is to have the same in one line . Please assist (3 Replies)
Discussion started by: vinil
3 Replies

2. UNIX for Dummies Questions & Answers

Need help in writing shell script

Dear Team, Below is the list of steps i need to perform manually as of now and completely new to shell scripting, could you help in writing a shell script to perform the below procedure? 1. Log in to primary DNS server 2. Check /etc/named.conf if zone is already created (grep –i... (2 Replies)
Discussion started by: VKIRUPHAKARAN
2 Replies

3. Shell Programming and Scripting

Need help writing shell script!

Hi, I'm very new to this, so bear with me please. I want to write a sh script (or if there's a better format please let me know) that allows me to, when I run it, print the date to a file (1.out) take 2 arguments (files a.fa and b.fa), run them with another program, outputting to 2.out, and then... (2 Replies)
Discussion started by: ShiGua
2 Replies

4. Shell Programming and Scripting

Two problems when I am writing my own shell

Hi, guys: I am writing my own shell using c. I meet with two problems. First, when I use tcsetpgrp system call to move a background job to foreground, when this job finishes, my shell program also exit. What is the problem for that? Second, when I use signal , if the child has its own... (1 Reply)
Discussion started by: tomlee
1 Replies

5. Shell Programming and Scripting

Writing a shell script

Hi I have two files a.log and b.log . i need to append a.log and b.log so that at the end of first line in a.log i need the append the data of first line from b.log and end of the second line in a.log i need to append the data of second line from b.log and so on up to the end of the file can... (3 Replies)
Discussion started by: lalu
3 Replies

6. Shell Programming and Scripting

seeking help with shell script

I am trying to update a script which I had created to monitor tablespace usage. Originally the sql spooled out to a text file anything with more than 75% used. I have been asked to change this. Now the sql must spool out all tablespaces. The script I have to write should scan the file for... (4 Replies)
Discussion started by: Niadh
4 Replies

7. Shell Programming and Scripting

Writing shell script

Hi, I am a new for shell script. i need to write script using the following commands cd /usres/test # create directory mkdir temp+DATE( i need to append date ) #moving files from one directory to this directory(we need to check total files in source and taget) cd /users/sample ... (2 Replies)
Discussion started by: bmkreddy
2 Replies

8. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies

9. Shell Programming and Scripting

Need help for writing shell script

Hello ALL, I am fresher in Unix . i need help to write small shell script . Please help me unix guru. I am developing the internal site in my office . the data files are generated in one directory everyday . I have to write shell script to sort those files and put it is internal site . ... (3 Replies)
Discussion started by: deepa20
3 Replies

10. UNIX for Dummies Questions & Answers

Writing a shell Script

How to write a shell script file to read 5 numbers using a while loop. Finding the average, maximum and minumum for the numbers. Any help would be great. (1 Reply)
Discussion started by: Chin
1 Replies
Login or Register to Ask a Question