2010-06-24 41 views
12

假设我是一个大unix新手, - 我每15分钟通过cron运行一个curl请求。 - 卷曲主要是用于加载给出了一些参数的网页(PHP)充当like的脚本:如何运行多个curl请求,按顺序处理?

curl http://mysite.com/?update_=1

我想达成什么是运行另一个“脚本”使用本curl技术, - 每其他脚本运行 时间 - 其他脚本运行

之前,我已阅读,卷曲接受多个网址,在一个命令,但是我不能确定这是否会处理ulrs顺序或“并行”。

回答

22

这将最有可能对它们进行处理顺序(为什么不只是测试它)。但你也可以这样做:

1)创建一个名为curlrequests.sh 2文件),把它放在像这样一个文件:

curl http://mysite.com/?update_=1 
curl http://mysite.com/?update_=3 
curl http://mysite.com/?update_=234 
curl http://mysite.com/?update_=65 

3)保存文件并使其可执行使用chmod:

chmod +x curlrequests.sh 

4)运行文件:

./curlrequests.sh 

/path/to/file/curlrequests.sh 

作为一个侧面说明,你可以链的请求与& &,像这样:

curl http://mysite.com/?update_=1 && curl http://mysite.com/?update_=2 && curl http://mysite.com/?update_=3 

并执行并行使用&:

curl http://mysite.com/?update_=1 & curl http://mysite.com/?update_=2 & curl http://mysite.com/?update_=3 
+0

Timoty,将连锁请求像 卷曲http://mysite.com/?update_=1 &&卷曲http://mysite.com/?update_=2 && ...... 顺序执行? – Riccardo 2010-06-24 16:28:39

+0

是的,在大多数情况下它们会,但是如果其中一个应该以错误(0以外的返回值)结束,则不会执行以下操作。 – mbq 2010-06-24 23:22:26

+0

这对我来说非常完美。谢谢! – Riccardo 2010-06-25 08:27:29

1

写一个脚本,在需要的高阶双卷曲的请求,并通过cron运行它,就像

#!/bin/bash 
curl http://mysite.com/?update_=1 
curl http://mysite.com/?the_other_thing 
0

我想,这会使用更多的原生功能

//printing the links to a file 
$ echo "https://stackoverflow.com/questions/3110444/ 
https://stackoverflow.com/questions/8445445/ 
https://stackoverflow.com/questions/4875446/" > links_file.txt 


$ xargs curl < links_file.txt 

享受!