简体   繁体   English

Bash 脚本读取文件并在每一行上卷曲并在找到字符串时输出

[英]Bash Script to read file and curl on each line and output if string found

Trying to build a shell script which determines if the site is using PulseVPN or not.尝试构建一个 shell 脚本来确定该站点是否正在使用 PulseVPN。 The script takes a input file which contains a list of URLs, iterate each URL line by line, perform cURL operation and grep for specific string.该脚本采用一个包含 URL 列表的输入文件,逐行迭代每个 URL,执行 cURL 操作和 grep 特定字符串。 And if string found, display a echo message "Website using PulseVPN"如果找到字符串,则显示回显消息“使用 PulseVPN 的网站”

Here is my code -这是我的代码 -

Keyword="dana-na" # keyword to find for PulseSecure SSL VPN
while read -r line; 
do
if curl -s -L "$line" | grep "$keyword" > /dev/null
then
    # if the keyword is in the conent
    echo " The website $line is using Pulse Secure VPN" 
else
    echo "Pulse Secure VPN Not Found on $line"
fi
done < urls.txt

Problem The code is working but The problem here is when i include only one URL in input file.问题代码运行正常,但这里的问题是当我在输入文件中只包含一个 URL 时。 It gives correct result.它给出了正确的结果。 But if i include more than one URL in input file, then it gives incorrect results.但是如果我在输入文件中包含多个 URL,那么它会给出不正确的结果。 Can anyone explains why is this happening.任何人都可以解释为什么会发生这种情况。 Is anything wrong in code ?代码有什么问题吗?

It might be skipping over the last line due to how read works.由于读取的工作方式,它可能会跳过最后一行。 Try尝试

while read -r line || [[ -n $line ]];

Look at this post for more information.查看帖子以获取更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Bash脚本读取文本文件,然后将每一行输出到变量中 - Bash script to read a text file and then output each line into variables 如何使用bash脚本在文件中输出第一行curl结果 - How to output first line of curl result in a file with bash script 卷曲或读取 url 文本文件的每一行,然后将每行输出到标记为连续数字的单独文件 - 1 2 3 等 - Curl or read each line of url text file, then output each to separate files labelled as consecutive numbers- 1 2 3 etc 使用bash脚本逐行读取文件 - Read file line by line with bash script bash脚本逐行读取和echo到文件 - bash script read line by line and echo to file 如何在Bash脚本中逐行读取文件? - How to read file line by line in Bash script? Bash脚本只读取文件的第一行 - Bash script only read the first line of the file bash脚本,读取文件的每一行并存储到不同的变量(但没有找到命令消息) - bash script that reads each line of a file and stores to different variables (but got command not found message) 在bash脚本上的块中读取文件-块以匹配的字符串开头,并在找到异常字符串时停止 - Read file in blocks on bash script - blocks start with matched string and stop when exception String is found Bash:逐行循环遍历文件,找到特定的字符串并追加到每个后续行,直到找到相同的字符串 - Bash: loop through file line by line, find specific string and append to each subsequent line until same string is found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM