【发布时间】:2019-05-08 21:03:58
【问题描述】:
我有一个工作 shell 脚本,它读取一个包含 URL 的文本文件,每个 URL 都在单独的行中。 URL 从文件中并行读取并检查其状态代码,其中将响应写入 status-codes.csv。
如何将 url-list.txt 引用的原始 URL 写入 status-codes.csv 中输出的第一列?
status-codes.sh
#!/bin/bash
xargs -n1 -P 10 curl -u user:pass -L -o /dev/null --silent --head --write-out '%{url_effective},%{http_code},%{num_redirects}\n' < url-list.txt | tee status-codes.csv
url-list.txt
http://website-url.com/path-to-page-1
http://website-url.com/path-to-page-2
http://website-url.com/path-to-page-3
status-codes.csv (当前输出)
http://website-url.com/path-to-page-2,200,1
http://website-url.com/path-to-page-after-any-redirects,200,2
http://website-url.com/404,404,2
status-codes.csv (期望的输出)
http://website-url.com/path-to-page-2,http://website-url.com/path-to-page-2,200,1
http://website-url.com/path-to-page-1,http://website-url.com/path-to-page-after-any-redirects,200,2
http://website-url.com/path-to-page-3,http://website-url.com/404,404,2
【问题讨论】: