Visit Our UNIX and Linux User Community


To get the job status from second line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To get the job status from second line
# 1  
Old 11-13-2016
To get the job status from second line

I want to get the job status from the second line "SU" to a variable

Input:
Code:
Job Name   Last Start                 Last End      ST  Run/Ntry   Pri/Xit 
JOBNAME   10/24/2016 10:34:55  10/24/2016 10:44:15  SU  100344/32  0

Code tried
Code:
JSTATUS=$(cat Input | awk '$6 == "SU" {print $6}')

Desired output:
Code:
echo $JSTATUS 
SU

But when job is running, "Last End" goes empty and I cant search with $6, is there a way to search first row "ST" and then get the respective below status?

Last edited by Joselouis; 11-13-2016 at 03:01 AM.. Reason: alignment
# 2  
Old 11-13-2016
Hello Joselouis,

Could you please try following and let me know if this helps you.
Code:
JSTATUS=$(awk 'NR==2 && NF==8{print $6}'  Input_file)
echo $JSTATUS

Above code will check each time line number 2nd and then will check if number of fields are 8, if this condition is satisfied then only it will print 6th field as per your request, could you please try above and let me know how it goes then.

EDIT: I saw you have edited your post and added condition of checking first line of looking for string ST and look for the same field on 2nd line, this could be done but in your shown sample Input_file seems value of string ST is coming on a lesser field than what it is on first line if this is a typo then following may hep you in same.
Code:
awk 'NR==1{for(i=1;i<=NF;i++){if($i=="ST"){Q=i}};next} {print $Q}'  Input_file

If your sample Input_file is NOT having typo and each time value of string ST will be in 1 field lessser than 1st line then you could tweak the code as follows too.
Code:
awk 'NR==1{for(i=1;i<=NF;i++){if($i=="ST"){Q=i}};next} {print $(Q-1)}'   Input_file

NOTE: Considering our Input_file will have only 2 lines.

Thanks,
R. Singh

Last edited by RavinderSingh13; 11-13-2016 at 03:22 AM.. Reason: Added new solution as per OP's new edited requirement successfully now.
# 3  
Old 11-13-2016
How about using the third last field
Code:
JSTATUS=$(awk 'NR==2{print $(NF-2)}' Input)

or the two characters at position 53-54:
Code:
JSTATUS=$(awk 'NR==2{print substr($0,53,2)}' Input)

# 4  
Old 11-13-2016
Here is another one:

Code:
awk 'NR==1 {a=index($0,"ST")} NR>1 { print substr($0,a,2)} ' file

Assuming line contains JOBNAME has two characters is what you want .
# 5  
Old 11-14-2016
if the autosys job is in RU/ST status, then we will only have 6 fields. so we have to get the status of the job like this..

Code:
awk 'NR>1&&NF==6{print $(NF-2)}NR>1&&NF==8{print $(NF-3)}' Input

# 6  
Old 11-16-2016
Thanks a lot for all your input, everything really helped

And also I got another autosys way to do it

Code:
autostatus -j JOBNAME

Above command gave me the status.. thank you all

Previous Thread | Next Thread
Test Your Knowledge in Computers #423
Difficulty: Medium
C# is a general-purpose, multi-paradigm programming language encompassing strong typing, lexically scoped, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get status of dd running in background job

Hello everyone While working on TUI for scripts, there there came the idea to' add a command' for dd too. That was, after 'wrapping' tar and wget either, to display their growing size and return the exit code with a textual-visual-feedback to the user. Now displaying the filesize of a... (13 Replies)
Discussion started by: sea
13 Replies

2. UNIX for Dummies Questions & Answers

Shell script - Finding Autosys job status

Hi, There are 2000 jobs in the list and i need to draw their status. I put all the jobs in the list and trying to read one by one from the list and to find out the status. Help me out in correcting the script. #!/bin/csh for a in $(cat Jobs_List.txt); do source <<path>> autorep -j $a... (1 Reply)
Discussion started by: venkatesht
1 Replies

3. Shell Programming and Scripting

automatically check job status

I have written a BASH script to autmatically start several jobs. I want to add additional function to the script so it would check these jobs from time to time (the jobs could take as short as 2 hours or as long as 1 day to finish). If a job is done, check the log file and output the error into a... (3 Replies)
Discussion started by: momentum
3 Replies

4. UNIX for Advanced & Expert Users

Check the status of job

Hi, I have master job which will run based on the sub jobs status. In the master job I am giving the condition like, condition: s(sub_job) f(sub_job) This scenario will work if the sub job status is success or failed. but I want to run my master job even if the sub_job was... (1 Reply)
Discussion started by: Kattoor
1 Replies

5. UNIX for Dummies Questions & Answers

How to findsuccessful job status completion in Autosys, programatically

We are using autosys for job scheduling. How to find successful job status completion in Autosys, programatically. Based on the successful job completion , mail has to be trigeered to Business users. Please help Thanks (0 Replies)
Discussion started by: vkalya
0 Replies

6. UNIX for Dummies Questions & Answers

Job Status for running shell script

Hello, I am running a shell script whose execution often takes several hours to complete. Is there way I can get some kind of status update as the job is running? Something as simple as the start and the current time stamp. Thanks, Gussi (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

7. Shell Programming and Scripting

check status and run the job

I have one unix job which can be executed using following commands: csh setenv HOME /data/ftpqa/ARTQ/orascripts sudo -u artq /apps/ralocal/bin/runscript artq ../out/art_neg_item_cost_update.csh I want to create one more script, which checks whether art_neg_item_cost_update.csh is already... (1 Reply)
Discussion started by: amarpreetka
1 Replies

8. Shell Programming and Scripting

Terminal And Cron Job Return Different Status Code

Dear All, I want to write a shell script to test the server is running or not. The method is pinging the server and examine the status code. the script: #/bin/tcsh ping -c 3 host if ($? != 0) then actionA endif This script work fine in terminal. The status code is 0 when the... (1 Reply)
Discussion started by: isaac_ho
1 Replies

9. Programming

Status of child job after parent is killed

Hi, I have a requirement. Scenario: A parent job invokes a child job and gets killed. The child becomes orphan and gets attached to init. Child job is removed from the pid table as soon as it gets completed. Requirement is i need the status of the child job even after the parent job is... (7 Replies)
Discussion started by: anjul_thegreat
7 Replies

10. Shell Programming and Scripting

Hw to Know the status of running JoB

Hi all, I am running a job .. and i want to know the status tht it is runnig or not .. and how can i find the jobId of my job .. I have to get it to kill my running job Pls let me know da Unix commands to do it .. i m wrking on Hp UNIX (1 Reply)
Discussion started by: ravi.sadani19
1 Replies

Featured Tech Videos