从bash脚本parallel
执行5个curl
请求的最好方法是什么? 性能方面,我无法连续运行它们。
在命令后面使用'&'来后台进程,'等待'等待它们完成。 如果需要创build子shell,请在命令周围使用“()”。
#!/bin/bash curl -s -o foo http://example.com/file1 && echo "done1" & curl -s -o bar http://example.com/file2 && echo "done2" & curl -s -o baz http://example.com/file3 && echo "done3" & wait
xargs有一个“-P”参数来并行运行进程。 例如:
wget -nv http://en.wikipedia.org/wiki/Linux -O- | egrep -o "http://[^[:space:]]*.jpg" | xargs -P 10 -r -n 1 wget -nv
参考: http : //www.commandlinefu.com/commands/view/3269/parallel-file-downloading-with-wget
我使用gnu并行执行这样的任务。