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

関連情報