Trying to build a shell script which determines if the site is using PulseVPN or not. 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. And if string found, display a echo message "Website using 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. It gives correct result. But if i include more than one URL in input file, then it gives incorrect results. Can anyone explains why is this happening. Is anything wrong in code ?
grep -q "$keyword"is more efficient thangrep "$keyword" >/dev/null, as the former (but not the latter) can stop as soon as the first match is found, instead of reading to the end of the file and writing content to/dev/null.bash -x yourscriptto trace the individual commands that get run and compare them against what you expect. For example, if you see your line being displayed with$'\r'characters at the end, then you know there's a newline type problem; if you see''used instead of your keyword, you know to look at that (and can figure out theKeyword/keywordname mismatch issue), etc.curl <&- ...to make sure it's not reading data intended forread.