LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   to check the job status basis on multiple pattern (https://www.linuxquestions.org/questions/linux-newbie-8/to-check-the-job-status-basis-on-multiple-pattern-4175516737/)

azheruddin 08-29-2014 04:03 AM

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 ***** ]

azheruddin 08-29-2014 10:27 AM

can any one help me to write my script.

TB0ne 08-29-2014 10:42 AM

Quote:

Originally Posted by azheruddin (Post 5229313)
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.

azheruddin 08-31-2014 03:32 AM

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

unSpawn 08-31-2014 05:50 AM

Quote:

Originally Posted by azheruddin (Post 5230061)
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 ?

azheruddin 08-31-2014 07:02 AM

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..

TB0ne 08-31-2014 04:21 PM

Quote:

Originally Posted by azheruddin (Post 5230122)
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.

azheruddin 08-31-2014 10:05 PM

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.

TB0ne 09-01-2014 09:07 AM

Quote:

Originally Posted by azheruddin (Post 5230454)
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.

azheruddin 09-01-2014 09:29 AM

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

TB0ne 09-01-2014 05:52 PM

Quote:

Originally Posted by azheruddin (Post 5230678)
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.

unSpawn 09-01-2014 06:06 PM

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).



All times are GMT -5. The time now is 05:42 AM.