CURL - 保存多個 HTTP 回應

CURL - 保存多個 HTTP 回應

我了解到我們可以透過執行以下操作使用 CURL 發送多個 HTTP 請求:

curl -I http://linuxbyexample.co.nr http://lne.blogdns.com/lbe

或這個:

xargs curl -I < url-list.txt

我們如何才能將收到的所有回應(每一個回應)保存到不同的文件中?

答案1

您可以使用-o命令列選項將輸出寫入檔案而不是 stdout。您可以使用多個-os 例如

curl -I http://linuxbyexample.co.nr lbe.co.nr.txt http://lne.blogdns.com/lbe -o lne.txt

如果你像這樣格式化 urls-list.txt

http://serverfault.com -o serverfault.com.txt
http://example.com -o example.com.txt

它應該按你想要的方式工作。

答案2

$ cat urls-list.txt 
http://linuxbyexample.co.nr 
http://lne.blogdns.com/lbe

$ while read u; do \
    curl -I $u -o $(echo $u | sed 's/http:\/\///' | tr '/' '_').header; \
done < urls-list.txt

$ cat linuxbyexample.co.nr.header 
HTTP/1.1 200 OK
Date: Thu, 24 Nov 2011 03:15:19 GMT
Server: LiteSpeed
Connection: close
X-Powered-By: PHP/5.2.10
Content-Type: text/html
X-Powered-By: PleskLin

相關內容