![CURL - 保存多個 HTTP 回應](https://rvso.com/image/568252/CURL%20-%20%E4%BF%9D%E5%AD%98%E5%A4%9A%E5%80%8B%20HTTP%20%E5%9B%9E%E6%87%89.png)
我了解到我們可以透過執行以下操作使用 CURL 發送多個 HTTP 請求:
curl -I http://linuxbyexample.co.nr http://lne.blogdns.com/lbe
或這個:
xargs curl -I < url-list.txt
我們如何才能將收到的所有回應(每一個回應)保存到不同的文件中?
答案1
您可以使用-o
命令列選項將輸出寫入檔案而不是 stdout。您可以使用多個-o
s 例如
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