1

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
1
  • 1
    What are the contents of ip2.txt and did you ever edit that file in Windows? Could it have Windows line endings? Commented May 26, 2022 at 9:20

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.