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
# 8  
Old 08-27-2014
Today's the 27th, the record you want is on the 28th, so it doesn't match.
# 9  
Old 08-28-2014
Hi Rudie/Corona,

Even if iam searching the for today's log no output is coming even though for the today's date job got success.

So the main purpose of this job to check the status of the job, as below
Code:
"abcd.job" (abcd.bat)
        Finished 8/28/2014 5:07:17 AM
        Result: The task completed with an exit code of (0).

If it success then it should give message like job successfully executes else job got fail.
# 10  
Old 08-28-2014
Surprise - it's working today (28.Aug.2014)!
Code:
sed 's/^"/\n"/' file3 | 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)
        Finished 8/28/2014 5:07:17 AM
        Result: The task completed with an exit code of (0).


Last edited by RudiC; 08-28-2014 at 05:59 AM..
# 11  
Old 08-28-2014
Hi Corona,

Sorry to say but still code doesn't work as expected.

cant we have a other way by greping multiple pattern like date, jobname, and status code , if the abcd.job for the current date have the status as
Code:
Result: The task completed with an exit code of (0)

then it will log the success in a new log else job got failed.

pasting here complete log file...

HTML Code:
"abcd.job" (abcd.bat)
        Started 8/24/2014 5:00:00 AM
"abcd.job" (abcd.bat)
        Finished 8/24/2014 5:07:04 AM
        Result: The task completed with an exit code of (0).
"CRF Analysis.job" (CRF Analysis.bat)
        Started 8/24/2014 7:00:00 AM
"Eventlog.job" (Event_clear.vbs)
        Started 8/24/2014 7:00:01 AM
"Eventlog.job" (Event_clear.vbs)
        Finished 8/24/2014 7:00:06 AM
        Result: The task completed with an exit code of (0).
"CRF Analysis.job" (CRF Analysis.bat)
        Finished 8/24/2014 7:00:09 AM
        Result: The task completed with an exit code of (0).
"abcd.job" (abcd.bat)
        Started 8/25/2014 5:00:00 AM
"abcd.job" (abcd.bat)
        Finished 8/25/2014 5:06:58 AM
        Result: The task completed with an exit code of (0).
"CRF Analysis.job" (CRF Analysis.bat)
        Started 8/25/2014 7:00:00 AM
"CRF Analysis.job" (CRF Analysis.bat)
        Finished 8/25/2014 7:00:08 AM
        Result: The task completed with an exit code of (0).
"abcd.job" (abcd.bat)
        Started 8/26/2014 5:00:00 AM
"abcd.job" (abcd.bat)
        Finished 8/26/2014 5:07:01 AM
        Result: The task completed with an exit code of (0).
"CRF Analysis.job" (CRF Analysis.bat)
        Started 8/26/2014 7:00:00 AM
"CRF Analysis.job" (CRF Analysis.bat)
        Finished 8/26/2014 7:00:08 AM
        Result: The task completed with an exit code of (0).
"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).
"CRF Analysis.job" (CRF 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).
"CRF Analysis.job" (CRF Analysis.bat)
        Finished 8/27/2014 7:00:10 AM
        Result: The task completed with an exit code of (0).
"abcd.job" (abcd.bat)
        Started 8/28/2014 5:00:00 AM
"abcd.job" (abcd.bat)
        Finished 8/28/2014 5:07:05 AM
        Result: The task completed with an exit code of (0).
"abcd.job" (abcd.bat)
        Started 8/29/2014 5:00:00 AM
"abcd.job" (abcd.bat)
        Finished 8/29/2014 5:07:05 AM
        Result: The task completed with an exit code of (0).
"CRF Analysis.job" (CRF Analysis.bat)
        Started 8/28/2014 7:00:00 AM
"CRF Analysis.job" (CRF Analysis.bat)
        Finished 8/28/2014 7:00:09 AM
        Result: The task completed with an exit code of (0).
[ ***** Most recent entry is above this line ***** ]
"abcd.job" (abcd.bat)
        Started 8/24/2014 5:00:00 AM
"abcd.job" (abcd.bat)
        Finished 8/24/2014 5:07:04 AM
        Result: The task completed with an exit code of (0).
"CRF Analysis.job" (CRF Analysis.bat)
        Started 8/24/2014 7:00:00 AM
"Eventlog.job" (Event_clear.vbs)
        Started 8/24/2014 7:00:01 AM
"Eventlog.job" (Event_clear.vbs)
        Finished 8/24/2014 7:00:06 AM
        Result: The task completed with an exit code of (0).
"CRF Analysis.job" (CRF Analysis.bat)
        Finished 8/24/2014 7:00:09 AM
        Result: The task completed with an exit code of (0).
"abcd.job" (abcd.bat)
        Started 8/25/2014 5:00:00 AM
"abcd.job" (abcd.bat)
        Finished 8/25/2014 5:06:58 AM
        Result: The task completed with an exit code of (0).
"CRF Analysis.job" (CRF Analysis.bat)
        Started 8/25/2014 7:00:00 AM
"CRF Analysis.job" (CRF Analysis.bat)
        Finished 8/25/2014 7:00:08 AM
        Result: The task completed with an exit code of (0).
"abcd.job" (abcd.bat)
        Started 8/26/2014 5:00:00 AM
"abcd.job" (abcd.bat)
        Finished 8/26/2014 5:07:01 AM
        Result: The task completed with an exit code of (0).
"CRF Analysis.job" (CRF Analysis.bat)
        Started 8/26/2014 7:00:00 AM
"CRF Analysis.job" (CRF Analysis.bat)
        Finished 8/26/2014 7:00:08 AM
        Result: The task completed with an exit code of (0).
"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).
"CRF Analysis.job" (CRF 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).
"CRF Analysis.job" (CRF Analysis.bat)
        Finished 8/27/2014 7:00:10 AM
        Result: The task completed with an exit code of (0).
"abcd.job" (abcd.bat)
        Started 8/29/2014 5:00:00 AM
"abcd.job" (abcd.bat)
        Finished 8/29/2014 5:07:05 AM
        Result: The task completed with an exit code of (0).
"CRF Analysis.job" (CRF Analysis.bat)
        Started 8/28/2014 7:00:00 AM
"CRF Analysis.job" (CRF Analysis.bat)
        Finished 8/28/2014 7:00:09 AM
        Result: The task completed with an exit code of (0).
[ ***** Most recent entry is above this line ***** ]
# 12  
Old 08-29-2014
Quote:
Originally Posted by ajju
Hi Corona,

Sorry to say but still code doesn't work as expected.
It fulfilled your specifications and worked on the data you gave. If you wanted dates from the future instead of today's, you could have informed the program of that, or at least informed me of that. Perhaps I was being too "clever" and automating it when all you wanted was something easy to plug values you wanted into?

What you were expecting was -- and remains -- unclear. Tell me exactly what you wish to match for, and exactly what output you expect from it, don't tell me my code is bad for not reading your mind.

Quote:
cant we have a other way by greping multiple pattern like date, jobname, and status code
That's exactly what I did. The sed chops it into blocks so awk knows where records begin and end, and beyond that, you can do whatever you please.

"grep" doesn't work that way of course -- it matches lines and only lines. If you want something which understands "if line 1 matches something, do something with line 2, print part of line 3, delete part of line 4" that's exactly what awk is for.

I'll keep my example simpler this time, less chance of misunderstanding, and it's easier to improve a working script than figure out what a broken one's supposed to do.
Code:
sed 's/^"/\n"/' np_log.txt | awk '$1 ~ FILE { print }' RS="" FS="\n" OFS="\n" ORS="\n" FILE="abcd.job" -

Red is the actual awk program -- in this case, just "print the entire record if the first field matches FILE". I had it as index() before to make it more robust, this is a simpler illustration of what I'm doing.

Green defines variables. I moved them to the back to make it clearer. RS, FS, OFS, ORS are special variables, tailored to your data here so a "record" is exactly one data block and a "field" is exactly one line( so line 1 is $1, line 2 is $2, etc, $NF is the last line, $0 is the entire data block, etc).

Blue is the input file to read. There can be one or more. - reads from standard input.

Last edited by Corona688; 08-29-2014 at 01:33 PM..
# 13  
Old 09-01-2014
Quote:
Originally Posted by Corona688
It fulfilled your specifications and worked on the data you gave. If you wanted dates from the future instead of today's, you could have informed the program of that, or at least informed me of that. Perhaps I was being too "clever" and automating it when all you wanted was something easy to plug values you wanted into?

What you were expecting was -- and remains -- unclear. Tell me exactly what you wish to match for, and exactly what output you expect from it, don't tell me my code is bad for not reading your mind.

That's exactly what I did. The sed chops it into blocks so awk knows where records begin and end, and beyond that, you can do whatever you please.

"grep" doesn't work that way of course -- it matches lines and only lines. If you want something which understands "if line 1 matches something, do something with line 2, print part of line 3, delete part of line 4" that's exactly what awk is for.

I'll keep my example simpler this time, less chance of misunderstanding, and it's easier to improve a working script than figure out what a broken one's supposed to do.
Code:
sed 's/^"/\n"/' np_log.txt | awk '$1 ~ FILE { print }' RS="" FS="\n" OFS="\n" ORS="\n" FILE="abcd.job" -

Red is the actual awk program -- in this case, just "print the entire record if the first field matches FILE". I had it as index() before to make it more robust, this is a simpler illustration of what I'm doing.

Green defines variables. I moved them to the back to make it clearer. RS, FS, OFS, ORS are special variables, tailored to your data here so a "record" is exactly one data block and a "field" is exactly one line( so line 1 is $1, line 2 is $2, etc, $NF is the last line, $0 is the entire data block, etc).

Blue is the input file to read. There can be one or more. - reads from standard input.
Thanks, can we add log after the given statement to check that job for the current completed or not...
# 14  
Old 09-04-2014
Show input and corresponding output. Relevant input and relevant output. I don't want to be testing the wrong thing again.
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