LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-29-2014, 04:03 AM   #1
azheruddin
Member
 
Registered: Dec 2011
Posts: 83
Blog Entries: 1

Rep: Reputation: Disabled
to check the job status basis on multiple pattern


Hi All,

I am writing one script to check the status of my job by checking the log file, is that completed or not ,I have one scheduler log file which i am downloading from windows server to AIX and searching the current date, job name and status code, getting issues to fix it by awk -v RS="" -v FS="\n" -v D="$(date +/%m/%d/%Y)".

in the log file date is in windows format 8/29/2014 .

please refer the below log file, so wanted to check for the current date abcd.job has finished successfully on the basis of completion code.if success it should give success message else failure.

"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/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 ***** ]
 
Old 08-29-2014, 10:27 AM   #2
azheruddin
Member
 
Registered: Dec 2011
Posts: 83
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
can any one help me to write my script.
 
Old 08-29-2014, 10:42 AM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,504

Rep: Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993
Quote:
Originally Posted by azheruddin View Post
can any one help me to write my script.
You have posted several threads where you are, essentially, asking people to write scripts for you.
http://www.linuxquestions.org/questi...on-4175438073/
http://www.linuxquestions.org/questi...pt-4175440649/
http://www.linuxquestions.org/questi...pt-4175444590/
http://www.linuxquestions.org/questi...at-4175448079/

We WILL be happy to help you, but you have to post what YOU have written/tried on your own first, and tell us where you're stuck. If you want someone to write your scripts for you, then post this in the LQ Job Marketplace, along with how much you want to PAY SOMEONE to do your work, and someone will be happy to.

You have been working with Linux for three years now...there are MANY scripting tutorials available, and you've been given samples before. Apply what you've learned and show some effort.

Last edited by TB0ne; 08-29-2014 at 10:46 AM.
 
Old 08-31-2014, 03:32 AM   #4
azheruddin
Member
 
Registered: Dec 2011
Posts: 83
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
This is what i have tried ...

awk -v RS="" -v FS="\n" -v D="$(date +/%m/%d/%Y)" but getting NIL output for every case...

so wanted to check for the current date abcd.job has finished successfully on the basis of completion code.if success it should give success message else failure
 
Old 08-31-2014, 05:50 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,335
Blog Entries: 55

Rep: Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535
Quote:
Originally Posted by azheruddin View Post
This is what i have tried ...
Code:
awk -v RS="" -v FS="\n" -v D="$(date +/%m/%d/%Y)"
but getting NIL output for every case...
What you seem to have done is declare a few variables but you have not actually done anything with them. Maybe you should start with http://www.grymoire.com/Unix/Awk.html and http://www.gnu.org/software/gawk/manual/gawk.html ?
 
Old 08-31-2014, 07:02 AM   #6
azheruddin
Member
 
Registered: Dec 2011
Posts: 83
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
sed 's/^"/\n"/' filename | awk -v RS="" -v FS="\n" -v D="$(date +/%m/%d/%Y)" -v JOB="abcd.job" 'BEGIN { gsub("/0", "/", D); D=substr(D,2); } ;

Output is NIL...

So first finding the current date in file , then job name for the current date and its status (exit code),problem is in either of the case its giving NIL out put..
 
Old 08-31-2014, 04:21 PM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,504

Rep: Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993
Quote:
Originally Posted by azheruddin View Post
sed 's/^"/\n"/' filename | awk -v RS="" -v FS="\n" -v D="$(date +/%m/%d/%Y)" -v JOB="abcd.job" 'BEGIN { gsub("/0", "/", D); D=substr(D,2); } ;

Output is NIL... So first finding the current date in file , then job name for the current date and its status (exit code),problem is in either of the case its giving NIL out put..
Right, because again, as unSpawn said, you are declaring things, but not actually USING THEM.

If you want to 'debug' the line you posted, type in one command at a time, and see what the output is after each step. Personally, given the input data, I'd use grep to grab the jobs..pay particular attention to the -A and -B flags on the grep man page. That will get you the 'group' around the abcd.job lines, and you can shove that whole thing into an array, and process it accordingly.
 
Old 08-31-2014, 10:05 PM   #8
azheruddin
Member
 
Registered: Dec 2011
Posts: 83
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Thanks , As you Quated below , that is what i was looking for assistance not for complete solution..

grouping the lines into array...
That will get you the 'group' around the abcd.job lines, and you can shove that whole thing into an array, and process it accordingly.
 
Old 09-01-2014, 09:07 AM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,504

Rep: Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993
Quote:
Originally Posted by azheruddin View Post
Thanks , As you Quated below , that is what i was looking for assistance not for complete solution..

grouping the lines into array...
That will get you the 'group' around the abcd.job lines, and you can shove that whole thing into an array, and process it accordingly.
When you post no code of your own, and ask people to 'help you write your script' over and over, without ever actually SHOWING US any of your own work, it certainly seems like you were (again), asking someone to write your scripts.

There are many scripting tutorials you could have easily found to show you how to do what you're after.
 
Old 09-01-2014, 09:29 AM   #10
azheruddin
Member
 
Registered: Dec 2011
Posts: 83
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
This is what i have written and achieved the expected result and i was expecting a a one line snippet to sort out the the things not the entire script which is more than 100 lines and which is already written by me.

Anyway marking this thread as resolved, thanks all for your valuable time.

Quote:
awk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=1 a=1 s="`date +%-m/%-d/%Y`" test.Txt | sed -n '1,/CRF/p' | tail -10 > temp_log.txt

grep "task completed with an exit code of (0)" temp_log.txt
if [ $? -eq 0 ]; then
echo " --- job ran successfully --- " > status.log
else
echo " --- job Failed ---" > status.log
fi
 
Old 09-01-2014, 05:52 PM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,504

Rep: Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993
Quote:
Originally Posted by azheruddin View Post
This is what i have written and achieved the expected result and i was expecting a a one line snippet to sort out the the things not the entire script which is more than 100 lines and which is already written by me.
Then why didn't you post it, since you were asked for it many times?
Quote:
Anyway marking this thread as resolved, thanks all for your valuable time.
Glad it's working.
 
Old 09-01-2014, 06:06 PM   #12
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,335
Blog Entries: 55

Rep: Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535
Bit crude but couldn't you just
Code:
awk '/exit code/ {if(substr($10,2,1) != 0)print}' test.Txt
?
That should result in something (example) like this:
Code:
Result: The task completed with an exit code of (127).
Result: The task completed with an exit code of (1).
 
  


Reply

Tags
aix, awk, date, grep, shell scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to find out which job has start status but no end status ajdba Linux - General 1 01-14-2013 03:35 PM
svcadm: Pattern 'nfs/status' doesn't match any instances AlucardZero Solaris / OpenSolaris 2 06-11-2010 08:23 AM
LXer: HowTo check the status of one or multiple network interfaces the easy way LXer Syndicated Linux News 0 04-04-2009 04:11 PM
AWK/SED Multiple pattern matching over multiple lines issue GigerMalmensteen Programming 15 12-03-2006 05:08 PM
cron job status - how to ? mofo Linux - Software 0 12-14-2004 06:56 PM


All times are GMT -5. The time now is 07:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration