3

I am running a bash script as like that:

for i in {0..3250000..50000}
  do
    wget "http://xxx/select?q=*:*&row_size=50000&start=$i" -O $i.csv
  done

Every time when I send a request I have to wait to finish it and write to a file and after that it continues to looping. However I want to do it asynchronously. I mean that it will send a request and loop without waiting response. However when a response comes it will do the proper thing.

How can I do that?

4

2 回答 2

3

您可以使用xargs

printf '%s\0' {0..50000..3250000} |
    xargs -0 -I {} -n 1 -P 20 \
    wget 'http://xxx/select?q=*:*&row_size=50000&start={}' -O {}.csv

选择-0NULL 字符作为分隔符,用参数-I {}替换,将单个参数移交给并 一次处理 20 个请求,并行。{}-n 1wget-P 20

或者,您可以将 a 附加&到命令行以在后台执行它并wait完成进程。

于 2013-07-17T11:01:51.013 回答
1

您可以使用以下命令执行它。&在后台执行命令。

<cmd> &

但是您的循环看起来很大,它将在后台运行。控件将返回给脚本。因此,为避免执行问题,您应该编写一些函数来检查后台操作是否已退出。

于 2013-07-17T10:45:53.973 回答