npaluskar
npaluskar

Reputation: 63

How can i check the exit code of individual process running in parallel executed by GNU Parallel

I am having an array in linux shell script. Array contains list of commands in bash shell script. For instance :

 args =( "ls","mv /abc/file1 /xyz/file2","hive -e 'select * from something'" )

Now I am executing these commands in array using GNU parallel as bellow

parallel ::: "${args[@]}" 

I want to check the status code of individual process when they finish. I am aware that $? will give me the number of process which have failed but I want to know the exit code of individual process. How can I catch the exit codes of individual processes executed in GNU parallel?

Upvotes: 2

Views: 1007

Answers (2)

Ole Tange
Ole Tange

Reputation: 33715

--joblog logfile

Logfile for executed jobs. Save a list of the executed jobs to logfile in the following TAB separated format: sequence number, sshlogin, start time as seconds since epoch, run time in seconds, bytes in files transferred, bytes in files returned, exit status, signal, and command run.

Upvotes: 2

agc
agc

Reputation: 8406

Use the --halt 1 option, which makes parallel quit on the halting command, while returning it's exit code. From man parallel:

--halt-on-error val
--halt val
        How should GNU parallel terminate if one of more jobs fail?

        0      Do not halt if a job fails. Exit status will be the
               number of jobs failed. This is the default.

        1      Do not start new jobs if a job fails, but complete the
               running jobs including cleanup. The exit status will be
               the exit status from the last failing job.

        2      Kill off all jobs immediately and exit without cleanup.
               The exit status will be the exit status from the
               failing job.

        1-99%  If val% of the jobs fail and minimum 3: Do not start
               new jobs, but complete the running jobs including
               cleanup. The exit status will be the exit status from
               the last failing job.

Upvotes: 3

Related Questions