write a shell script to execute a command

Hello all,
I have just started doing shell scripting.
I want to read a file which stores the status of my job I have submitted
on a cluster.
The file looks something like this :
========================FILE=============================

crab: Checking the status of all jobs: please wait
crab:
ID STATUS E_HOST EXE_EXIT_CODE JOB_EXIT_STATUS
--------------------------------------------------------------------------------------------
1 Done
2 Done

crab: 2 Total Jobs

The highlighted lines display the status of the jobs. The status shown is done. Whenever it is done I want to give a command which is "getoutput" to retrieve my jobs.
So I want to write a small script which can read this file and whenever it is
done it just retrieves the output.
Could somebody tell me if there is a way to do this using shell script?

This is something which I tried doing but didnt work. "out" is file which stores the output info

==================================line========================================

flag[1]=0
flag[2]=0
cat out | gawk 'BEGIN{i=1;}{if($2=="Done") { $flag[i]=1; }'

if($flag[1]==1 && $flag[2]==1); then
getoutput
fi

But this doesnt seem to work because it seems that its treating flag[1] & flag[2] as local variables inside
gawk.

Thanks
learn_linux

$ 
$ cat file1
crab: Checking the status of all jobs: please wait
crab:
ID STATUS E_HOST EXE_EXIT_CODE JOB_EXIT_STATUS
--------------------------------------------------------------------------------------------
1 Done
2 Done

crab: 2 Total Jobs
$ 
$ awk '$2=="Done"' file1
1 Done
2 Done
$ 

tyler_durden

Hi,
Thanks for the reply. I do not want to print "Done".
I am running a job on a cluster. The output of which remains stored there until I say "getoutput" on my terminal which then brings the output on my hard disk. What I do is I first check the status of the job stored in a file "out" (in my case) and then if the job is done I say "getoutput".
I want to write a shell script which can execute a command "getoutput" (this is a command which is specific to a cluster I am working on) after checking if the job status is "Done".

I have written a line which is trying to do the same:

========================CODE====================
flag[1]=0
flag[2]=0
cat out | gawk 'BEGIN{i=1;}{if($2=="Done") { $flag[i]=1; i=i+1;}'

if($flag[1]==1 && $flag[2]==1); then
getoutput
fi

======================================================

But the problem here is that after the gawk is over, the values of flags are still 0 even if $2=="Done" i.e. gawk is not changing the value of flags globally (only locally) which should get changed if $2=="Done"

Thanks,
learn_linux

Is it a coincidence that you have declared two elements of that array when "Done" occurs twice in the "out" file ?

If "Done" had occurred thrice, would you have declared 3 array elements ? i.e. do you need to know the number of times "Done" occurs before you can declare the array elements ?

Or do you not care if "Done" occurs more than twice ? Which means you execute "getoutput" when "Done" occurs at least twice. (or is it exactly twice.)

tyler_durden

Hi,
I want to execute "getoutput" when "Done" appears exactly twice.

I think my problem would be solved if I know how to change the value of a shell
variable inside gawk.

This is something I tried :

flag[1]=0
flag[2]=0
cat out | gawk 'BEGIN{i=1; print "flag inside begin = "; print /'$flag[1]'/;} { if($2=="Done") { /{$flag[i]=1}/; i=i+1; print "flag [i]inside if = "; print /'$flag[i]'/; }} '

echo "flag after awk = "
echo {$flag[1]}

And here is the output:
============================output=============================
flag inside begin = 0
flag [i]inside if = 0
flag [i]inside if = 0
flag after awk = 0

Though I have tried changing the value of flag inside gawk by doing :
/{$flag[i]=1}/

It seems that inside awk, there is someother way to change the vaue of a shell variable.

Thanks,
learn_linux