这是HTTP状态代码的简单bash脚本
while read url
do
urlstatus=$(curl -o /dev/null --silent --head --write-out '%{http_code}' "${url}" --max-time 5 )
echo "$url $urlstatus" >> urlstatus.txt
done < $1
我正在从文本文件中读取URL,但是它一次只能处理一个,花费太多时间,GNU并行,并且一次xargs
也只能处理一行(经过测试)
如何处理同时URL以进行处理以改善计时?换句话说,URL文件的线程而不是bash命令的线程(与GNU并行xargs
执行)
Input file is txt file and lines are separated as
ABC.Com
Bcd.Com
Any.Google.Com
Something like this
。
GNU parallel和xargs一次也处理一行(已测试)
你能举个例子吗?如果使用,-j
则一次应该可以运行多个进程。
我会这样写:
doit() {
url="$1"
urlstatus=$(curl -o /dev/null --silent --head --write-out '%{http_code}' "${url}" --max-time 5 )
echo "$url $urlstatus"
}
export -f doit
cat "$1" | parallel -j0 -k doit >> urlstatus.txt
根据输入:
Input file is txt file and lines are separated as
ABC.Com
Bcd.Com
Any.Google.Com
Something like this
www.google.com
pi.dk
我得到的输出:
Input file is txt file and lines are separated as 000
ABC.Com 301
Bcd.Com 301
Any.Google.Com 000
Something like this 000
www.google.com 302
pi.dk 200
看起来正确的是:
000 if domain does not exist
301/302 for redirection
200 for success
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句