大网数据广告活动
服务器运维问答

Using parallel to run script without input

· 52CE 我爱测

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 purpos…

问题原文

原帖链接 · user1700840 · CC BY-SA 3.0

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.

社区高分解答

原帖链接 · jwfearn · CC BY-SA 3.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-06-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。