I have this script on a Linux machine that loops through a .txt file to see if connection is successful or not. When I give the IP directly is works. However, when I pass the variable it says: nc: getaddrinfo: nodename nor servname provided, or not known. Here is the my script:
#!/bin/bash
cat ip2.txt | while read line || [[ -n $line ]];
do
echo $line
if nc -zv $line 8080 ; then
echo "Success"
echo $line >> res.txt
else
echo "Fail"
fi
done
ip2.txtand did you ever edit that file in Windows? Could it have Windows line endings?