2012-02-09 192 views
6

我正尝试使用以下命令下载乱码异常日志。Curl:请求之间的睡眠/延迟

curl --cookie ./flurry.jar -k -L "https://dev.flurry.com/exceptionLogsCsv.do?projectID=49999&versionCut=versionsAll&intervalCut=allTime&direction=1&offset=[0-100:10]" --output "exception#1.csv" 

它工作正常,它会根据偏移量(10,20,30等)下载csv文件。我想在每个请求之间插入一个延迟。在CURL中可以这样做吗?

回答

4

使用bash外壳(Linux)的:

while : 
do 
    curl --cookie ./flurry.jar -k -L "https://dev.flurry.com/exceptionLogsCsv.do?projectID=49999&versionCut=versionsAll&intervalCut=allTime&direction=1&offset=[0-100:10]" --output "exception#1.csv" 
    sleep 5m 
done 

它是一个无限循环,并且延迟由sleep命令给出。

编辑。在Windows机器上,你可以做到这一点,而不是招:

for /L %i in (0,0,0) do (
    curl --cookie ./flurry.jar -k -L "https://dev.flurry.com/exceptionLogsCsv.do?projectID=49999&versionCut=versionsAll&intervalCut=allTime&direction=1&offset=[0-100:10]" --output "exception#1.csv" 
    ping -n XX 127.0.0.1>NUL 
) 

sleep命令不可用在Windows上。但是你可以使用ping来“模拟”它。只需将上面的XX替换为您想要延迟的秒数即可。

+0

我正在使用Windows如何在Windows中执行此操作? 。也看上面的代码,它似乎会反复运行相同的命令,这是不是我想要的。命令本身将迭代,因为我已经偏移= [0-100:10]。我想提到延迟或睡眠我的命令。可能吗? – rfsk2010 2012-02-09 15:15:49

+0

要迭代偏移量(10,20,30,...,100),用'(0,100,10)'替换上面的'(0,0,0)'。它意味着从0开始到100,增加10。但它不再是一个无限循环。 – 2012-02-09 15:28:24

+0

并将变量%i用于网址。所以它会是'...&offset =%i' – 2012-02-09 15:30:03

2

wget的具有延迟选项

wget --wait=seconds 

并且还随机延迟选项

wget --random-wait 
0

在bash,这将暂停在范围0-60秒的随机数:

for d in {0..100..10} 
do 
    i=`printf "%03d" $d` 
    curl --cookie ./flurry.jar -k -L 'https://dev.flurry.com/exceptionLogsCsv.do?projectID=49999&versionCut=versionsAll&intervalCut=allTime&direction=1&offset='$d --output 'exception'$i'.csv' 
    sleep $(($RANDOM*60/32767)) 
done