13

I'm trying to run many instances of a script with GNU parallel, but the script takes no arguments.

If I just execute 'parallel foo.sh' I get this:

parallel: Warning: Input is read from the terminal. Only experts do this on purpose. Press CTRL-D to exit.
user1700840
  • 313
  • 1
  • 3
  • 7

2 Answers2

15

Assuming you want to run ten times, this syntax will work:

parallel -n0 foo.sh ::: {1..10}

parallel needs an input sequence of some length (::: {1..10}) AND you need to ignore the contents of the input sequence(-n0), you only care about its length.

Your original command: parallel foo.sh, contains no input sequence to indicate how much parallelism you want. The cryptic warning is telling you that parallel is going to start listening to the terminal for an input sequence, and that this is probably not what you want.

Here's the tutorial example:

seq 10 | parallel -n0 my_command my_args

How it works:

  • parallel always takes an input sequence from somewhere. It can be an inline space-delimited sequence preceded by ::: OR a newline-delimited sequence from a file or filelike source such as a pipe. In this example the input sequence is from a pipe.
  • seq 10 produces a newline-delimited sequence of digits from one to ten.
  • The -n0 option tells parallel to ignore the values in the input sequence. All we care about is the length of the sequence, not its contents. Even though the digits aren't used, the command will still execute ten times.

Another example:

parallel -n0 echo -n 'x' ::: {1..5}

How it works:

  • Input sequence is inline.
  • {1..5} produces a space delimited sequence of digits from one to five.
  • -n0 ignores sequence values (and we echo the string 'x' each time instead.)
  • Output: xxxxx

Compare to:

parallel echo -n ::: {1..5}

How it works:

  • Input sequence is inline.
  • {1..5} produces a space delimited sequence of digits from one to five.
  • Each value from the input sequence is used as an argument to echo. Order not guaranteed.
  • Output: 43215. Could be any order.
jwfearn
  • 251
  • 2
  • 5
3

Did you read the examples in the manual? Specifically https://www.gnu.org/software/parallel/parallel.html#example-run-the-same-command-10-times

j824h
  • 3
  • 2
Ole Tange
  • 2,836
  • 5
  • 29
  • 45