To search the pattern on the basis of date and exit code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To search the pattern on the basis of date and exit code
# 1  
Old 08-27-2014
To search the pattern on the basis of date and exit code

Hi,

I am getting scheduler log file on daily basis from windows box which contains job status and corresponding date, date is in windows format.

I wanted to write one script which will search the pattern (Exit code) for the today's date and if code is Zero then Job Success message should be written in log else failure..

Log message is as below
Code:
"abcd.job" (abcd..bat)
	Started 8/27/2014 5:00:00 AM
"abcd.job" (abcd.bat)
	Finished 8/27/2014 5:07:00 AM
	Result: The task completed with an exit code of (0).
"PBC Analysis.job" (PBC Analysis.bat)
	Started 8/27/2014 7:00:00 AM
"Eventlog.job" (Event_clear.vbs)
	Started 8/27/2014 7:00:02 AM
"Eventlog.job" (Event_clear.vbs)
	Finished 8/27/2014 7:00:05 AM
	Result: The task completed with an exit code of (0).
"BUS Analysis.job" (BUS Analysis.bat)
	Finished 8/27/2014 7:00:10 AM
	Result: The task completed with an exit code of (0).
[ ***** Most recent entry is above this line ***** ]

So in the above log script will look only for the abcd.job and its result for the current date, other jobs should be ignore.

MY server is AIX, please assist.

Last edited by rbatte1; 08-27-2014 at 01:19 PM.. Reason: Spelling and CODE tags to replace HTML tags
# 2  
Old 08-27-2014
Hello ajju,

I have a few to questions pose in response first:-
  • What have you tried so far?
  • What output/errors do you get?
  • What OS version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
  • Are the sections without a Finished and Result record to be considered as failures or are they considered as running?
  • Is the format always the same?
Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.


We're all here to learn and getting the relevant information will help us all.

From
Quote:
date is in windows format
I would say that this is US format, but then that may not be correct either. Importantly, it appears that it is m/d/yyyy h:mi:ss AP so there is still a question of if there is a leading zero on the day. It would affect the options for the date command to work out the search string. Have a look at the manual page for datefor the options such as %d to see why it is important.

Have a look at the manual page for grep. As you are AIX, the -p flag may be of interest.

You will need to check what time of day you will be running this too, else you may actually need to look for the previous day's records and then you have to consider a calculation which AIX may not have built in to the date command in your version.



Regards,
Robin
# 3  
Old 08-27-2014
Code:
$ sed 's/^"/\n"/' input | awk -v RS="" -v FS="\n" -v D="$(date +/%m/%d/%Y)" -v JOB="abcd.job" 'BEGIN { gsub("/0", "/", D); D=substr(D,2); } ; index($1, "\""JOB"\"") && ($2 ~ D)'

"abcd.job" (abcd..bat)
        Started 8/27/2014 5:00:00 AM
"abcd.job" (abcd.bat)
        Finished 8/27/2014 5:07:00 AM
        Result: The task completed with an exit code of (0).

$

# 4  
Old 08-27-2014
Hi Corona688...

Third line:-
Code:
"abcd.job" (abcd..bat)

Is abcd..bat a valid Windows format?

Just curious...
# 5  
Old 08-27-2014
Why not? . is a valid character in a filename.
# 6  
Old 08-27-2014
NIL

thank you very much Coron

But I tried the given code its giving a NIL output though the command is running successfully.

Code:
sed 's/^"/\n"/' np_log.txt | awk -v RS="" -v FS="\n" -v D="$(date +/%m/%d/%Y)" -v JOB="abcd.job" 'BEGIN { gsub("/0", "/", D); D=substr(D,2); } ; index($1, "\""JOB"\"") && ($2 ~ D)'

No output is coming...

Np_log.txt containing the below pattern...

Code:
"CRF Analysis.job" (CRF Analysis.bat)
        Finished 8/26/2014 7:01:49 AM
        Result: The task completed with an exit code of (0).
"PULSS22.job" (PULLS22.bat)
        Started 8/26/2014 8:30:03 PM
"rtmas22.job" (rtmas22.bat)
        Finished 8/26/2014 8:33:40 PM
        Result: The task completed with an exit code of (0).
"abcd.job" (abcd.bat)
        Started /28/2014 5:00:02 AM
"abcd.job" (abcd.bat)
        Finished 8/28/2014 5:07:17 AM
        Result: The task completed with an exit code of (0).
"VRL Analysis.job" (VRL Analysis.bat)
        Started 8/27/2014 7:00:12 AM
"Eventlog.job" (Event_clear.vbs)
        Started 8/28/2014 7:00:17 AM
"Eventlog.job" (Event_clear.vbs)
        Finished 08/28/2014 7:00:19 AM
        Result: The task completed with an exit code of (1).
"VMR Analysis.job" (VMR Analysis.bat)
        Finished 8/28/2014 7:01:49 AM
        Result: The task completed with an exit code of (0).
"SPULL.job" (SPULL.bat)
         Started 8/28/2014 8:30:03 PM
"SPULL22.job" (SPULL22.bat)
        Finished 8/28/2014 8:33:40 PM
        Result: The task completed with an exit code of (0).
"WEC Analysis.job" (WEC Analysis.bat)
        Finished 8/28/2014 7:00:18 AM
        Result: The task completed with an exit code of (0).
"rtpbc22.job" (rtpbc22.bat) 8/28/2014 8:30:08 PM

Expected thing is just wanted to know what is the status of Job abcd.bat , if exit code is 0 then it shold through success message , else failure..
# 7  
Old 08-27-2014
Quote:
Originally Posted by ajju
.
.
.
No output is coming...
No surprise, given the sample file you provided. Corona688's proposal has two conditions joined by the AND operator:index($1, "\""JOB"\"") && ($2 ~ D)' (JOB holding "abcd.job"), of which the first is fulfilled by records 4 & 5, the second by record 6. No record satisfied both conditions, so no record is printed.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

2. Shell Programming and Scripting

Sorting on date basis

I have file data.txt having below data cat data.txt 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-JUN-13 2.38.11.00.100089 FC 1514 0000764631 01-NOV-13 2.38.11.00.100089 FC 1514 0000856571 01-NOV-13 2.38.11.00.100089 IN 300.32... (1 Reply)
Discussion started by: ranabhavish
1 Replies

3. Shell Programming and Scripting

Plz Help in sorting the data on date basis

I have file a.txt having below data cat a.txt 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-JUN-13 2.38.11.00.100089 IN 1514 0000764631 01-NOV-13 2.38.11.00.100089 IN 1514 0000856571 01-NOV-13 2.38.15.00.100015 IN 300.32 0000856531 01-JUN-13 2.38.19.00.100000 IN 2698 0000764493... (5 Replies)
Discussion started by: ranabhavish
5 Replies

4. UNIX for Dummies Questions & Answers

Plz Help in sorting the data on date basis

I have file having below data 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-JUN-13 2.38.11.00.100089 IN 1514 0000764631 01-NOV-13 2.38.11.00.100089 IN 1514 0000856571 01-NOV-13 2.38.15.00.100015 IN 300.32 0000856531 01-JUN-13 2.38.19.00.100000 IN 2698 0000764493 01-JUL-13... (2 Replies)
Discussion started by: ranabhavish
2 Replies

5. Solaris

Search date pattern in application log file

I am viewing a file in vi editor and would like to search for a date pattern. In the log, the timestamp is enclosed in parentheses ''. I am using the '/' option in vi to search for the pattern. log snippet: 000000f4 ServletWrappe I SRVE0242I: : Initialization successful. 000000f4... (3 Replies)
Discussion started by: Vangogh78
3 Replies

6. Shell Programming and Scripting

send an e-mail on the date basis

one of the script is writing as fallow . certification authority - exprire on July 16, 2056 How to send an e-mail to an e-mail id say abc@gmail.com one month before the expire date. Thanks (1 Reply)
Discussion started by: nagendramv
1 Replies

7. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies

8. Shell Programming and Scripting

Indexing or Filtering code- Pattern Search by comparing two files

So here is goes to the Gurus of shell programming......I have tried a lot of different ways and its a very challenging code to write but i am enjoying it as i troubleshoot and hopefully someone can provide me a better option....Thank you in advance for your time and support....Much appreciated... ... (12 Replies)
Discussion started by: aavam
12 Replies

9. UNIX for Dummies Questions & Answers

Where can I find a list of exit codes? (Exit code 64)

I'm receiving an exit code 64 in our batch scheduler (BMC product control-m) executing a PERL script on UX-HP. Can you tell me where I can find a list of exit codes and their meaning. I'm assuming the exit code is from the Unix operating system not PERL. (3 Replies)
Discussion started by: jkuchar747
3 Replies
Login or Register to Ask a Question