3

Suppose I have a list of commands in file cmd_file.

I run these commands via:

cat cmd_file | parallel -k -I {} "{}"

One of the commands fails. All of the commands use the exact same CLI tool with different inputs.

Right now, I have to run across all of the commands one at a time to find the erroring command by substituting my command list for a command builder loop (much more involved):

for ...; do
  # assemble the vars for the command
  echo "<command>"
  <command>
done

Is there a mechanic for getting parallel to display the command that failed, or the execution order onto stderr, for example?

Chris
  • 961
  • 7
  • 20

3 Answers3

4

You can instruct parallel to print each command executed either to standard output or to standard error. From the man page:

-v  Print the job to be run on stdout (standard output).
    Can be reversed with --silent. See also -t.

-t Print the job to be run on stderr (standard error).

So perhaps:

for ...; do
  # assemble the vars for the command
  echo "<command>"
done |
parallel -v -k

or if you have cmd_file already prepared:

parallel -v -k < cmd_file

or something similar will meet your needs.

Jim L.
  • 7,997
  • 1
  • 13
  • 27
1

If the command sets the exit value, --joblog is your friend.

Ole Tange
  • 35,514
1

Is there a mechanic for getting parallel to display the command that failed, or the execution order onto stderr, for example?

GNU Parallel 20220722 has --colour-failed:

parallel --tag --colour-failed "echo foo {}; {}" ::: true true false false true
Ole Tange
  • 35,514