头部-n /读取文件的问题

时间:2017-02-25 21:54:42

标签: bash shell ubuntu debian wget

    for ((zeile=1;zeile<=1284;zeile++));
do
  sleep 1.5
   export accountList=$(cat /root/pawnedDog/database/accountList | head -n${zeile})

   wget https://haveibeenpwned.com/api/v2/breachedaccount/${accountList}@gmail.com-P /root/pawnedDog/pawnedList/

done

我想创建一个shell脚本,检查整个电子邮件地址列表是否被黑客入侵。如果我运行脚本,wget命令开始下载gmail.com。我究竟做错了什么?

输出:

--2017-02-25 22:52:52--  https://haveibeenpwned.com/api/v2/breachedaccount/Adanna-Marie.Feder@gmail.com
Resolving haveibeenpwned.com (haveibeenpwned.com)... 2400:cb00:2048:1::6814:5b3a, 2400:cb00:2048:1::6814:5c3a, 104.20.92.58, ...
Connecting to haveibeenpwned.com (haveibeenpwned.com)|2400:cb00:2048:1::6814:5b3a|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-02-25 22:52:53 ERROR 404: Not Found.

--2017-02-25 22:52:54--  https://haveibeenpwned.com/api/v2/breachedaccount/Adanna-Marie.Feder
Resolving haveibeenpwned.com (haveibeenpwned.com)... 2400:cb00:2048:1::6814:5c3a, 2400:cb00:2048:1::6814:5b3a, 104.20.91.58, ...
Connecting to haveibeenpwned.com (haveibeenpwned.com)|2400:cb00:2048:1::6814:5c3a|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-02-25 22:52:55 ERROR 404: Not Found.

--2017-02-25 22:52:55--  http://Ada.Petriconi@gmail.com/
Resolving gmail.com (gmail.com)... 2a00:1450:4001:815::2005, 172.217.16.165
Connecting to gmail.com (gmail.com)|2a00:1450:4001:815::2005|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://www.google.com/gmail/ [following]
--2017-02-25 22:52:55--  https://www.google.com/gmail/
Resolving www.google.com (www.google.com)... 2a00:1450:4013:c05::69, 64.15.112.93, 64.15.112.89, ...
Connecting to www.google.com (www.google.com)|2a00:1450:4013:c05::69|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://mail.google.com/mail/ [following]
--2017-02-25 22:52:55--  https://mail.google.com/mail/
Resolving mail.google.com (mail.google.com)... 2a00:1450:4001:81c::2005, 172.217.16.165
Connecting to mail.google.com (mail.google.com)|2a00:1450:4001:81c::2005|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=googlemail&emr=1&osid=1 [following]
--2017-02-25 22:52:55--  https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=googlemail&emr=1&osid=1
Resolving accounts.google.com (accounts.google.com)... 2a00:1450:4001:819::200d, 172.217.23.141
Connecting to accounts.google.com (accounts.google.com)|2a00:1450:4001:819::200d|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘/root/pawnedDog/pawnedList/index.html.14’

/root/pawnedDog/pawnedList/index.html.14                 [ <=>                                                                                                                    ]  58.38K  --.-KB/s   in 0.05s

2017-02-25 22:52:55 (1.11 MB/s) - ‘/root/pawnedDog/pawnedList/index.html.14’ saved [59777]

FINISHED --2017-02-25 22:52:55--
Total wall clock time: 1.3s
Downloaded: 1 files, 58K in 0.05s (1.11 MB/s)

这是我的第一篇文章,我的英语不是很好。

1 个答案:

答案 0 :(得分:0)

您的文件/root/pawnedDog/database/accountList看起来每行有一个用户名。因此,您可以更有效地使用read重写循环:

while read -r account; do
  sleep 1.5
  wget https://haveibeenpwned.com/api/v2/breachedaccount/${account}@gmail.com -P /root/pawnedDog/pawnedList/
done < /root/pawnedDog/database/accountList

您的代码存在的问题是,head -n${zeile}会导致获取多个帐户(第一次迭代中为1个帐户,第二次中为2个帐户,3个等等)。您可以将管道编写为:

accountList=$(cat /root/pawnedDog/database/accountList | head -n${zeile}) | tail -1)

但是,这并不像在read循环中那样每次迭代读取一行有效。