GNU Parallel基础:如何提供一些不在最后位置的参数?

时间:2016-06-04 15:23:13

标签: gnu-parallel

如何使用 GNU Parallel 并行化 ping操作,如下所示?

ping -c 5 -S ${AdapterIP[1]} 8.8.8.8
ping -c 5 -S ${AdapterIP[2]} 8.8.8.8
ping -c 5 -S ${AdapterIP[3]} 8.8.8.8

问题:我正在使用 FreeBSD ,因此不允许进行此更改(请注意,ping的主机参数必须是最后一个)关于语法:

ping -c 5 8.8.8.8 -S ${AdapterIP[1]}

Linux 系统上,我只是这样做:

parallel ping -c 5 8.8.8.8 -S ::: "${AdapterIP[@]}"

我在FreeBSD上测试了这个方法:

    luis@Balanceador:~$ parallel ping -c 5 -S ::: "${AdapterIP[@]}" 8.8.8.8
usage: ping [-AaDdfnoQqRrv] [-c count] [-G sweepmaxsize] [-g sweepminsize]
            [-h sweepincrsize] [-i wait] [-l preload] [-M mask | time] [-m ttl]
            [-P policy] [-p pattern] [-S src_addr] [-s packetsize] [-t timeout]
            [-W waittime] [-z tos] host
       ping [-AaDdfLnoQqRrv] [-c count] [-I iface] [-i wait] [-l preload]
            [-M mask | time] [-m ttl] [-P policy] [-p pattern] [-S src_addr]
            [-s packetsize] [-T ttl] [-t timeout] [-W waittime]
            [-z tos] mcast-group
usage: ping [-AaDdfnoQqRrv] [-c count] [-G sweepmaxsize] [-g sweepminsize]
            [-h sweepincrsize] [-i wait] [-l preload] [-M mask | time] [-m ttl]
            [-P policy] [-p pattern] [-S src_addr] [-s packetsize] [-t timeout]
            [-W waittime] [-z tos] host
       ping [-AaDdfLnoQqRrv] [-c count] [-I iface] [-i wait] [-l preload]
            [-M mask | time] [-m ttl] [-P policy] [-p pattern] [-S src_addr]
            [-s packetsize] [-T ttl] [-t timeout] [-W waittime]
            [-z tos] mcast-group
usage: ping [-AaDdfnoQqRrv] [-c count] [-G sweepmaxsize] [-g sweepminsize]
            [-h sweepincrsize] [-i wait] [-l preload] [-M mask | time] [-m ttl]
            [-P policy] [-p pattern] [-S src_addr] [-s packetsize] [-t timeout]
            [-W waittime] [-z tos] host
       ping [-AaDdfLnoQqRrv] [-c count] [-I iface] [-i wait] [-l preload]
            [-M mask | time] [-m ttl] [-P policy] [-p pattern] [-S src_addr]
            [-s packetsize] [-T ttl] [-t timeout] [-W waittime]
            [-z tos] mcast-group

......没有运气,可以看出。

这可能是一个愚蠢的问题,但我是GNU Parallel的新手。请帮忙吗?

对于那些感兴趣的人,这是数组的可能值,它将为GNU Parallel提供信息:

luis@Balanceador:~$ echo ${AdapterIP[@]}
192.168.1.254 192.168.2.254 192.168.3.254

1 个答案:

答案 0 :(得分:1)

这是我发现在不在最后位置时指定参数的方式(--dry-run标志不执行,只是测试):

luis@Balanceador:~$ parallel --dry-run sudo ping -c 5 -S {1} 8.8.8.8 ::: "${AdapterIP[@]}"
sudo ping -c 5 -S 192.168.1.254 8.8.8.8
sudo ping -c 5 -S 192.168.2.254 8.8.8.8
sudo ping -c 5 -S 192.168.3.254 8.8.8.8

请注意{1} 它可以与多个参数一起使用。 {2}的示例:

luis@Balanceador:~$ parallel --dry-run sudo ping -c 5 -S {1} {2} ::: "${AdapterIP[@]}" ::: 8.8.8.8 8.8.4.4 
sudo ping -c 5 -S 192.168.1.254 8.8.8.8
sudo ping -c 5 -S 192.168.1.254 8.8.4.4
sudo ping -c 5 -S 192.168.2.254 8.8.8.8
sudo ping -c 5 -S 192.168.2.254 8.8.4.4
sudo ping -c 5 -S 192.168.3.254 8.8.8.8
sudo ping -c 5 -S 192.168.3.254 8.8.4.4