Check whether the port is Open on Multiple Remote CentOS Systems

Issues related to configuring your network
Post Reply
rameshreddy
Posts: 2
Joined: 2020/06/03 21:14:41

Check whether the port is Open on Multiple Remote CentOS Systems

Post by rameshreddy » 2020/06/03 21:26:15

Hi,

I tired below bash script, but it is getting failed! Could you please help on this?

I have multiple CentOS VM's and want to verify couple of ports are opened/listing or not among all these servers.

Code: Select all

#vi server-list.txt
test-1-001.child.domain.com
test-2-001.child.domain.com
test-3-002.child.domain.com
test-4-003.child.domain.com

Code: Select all

# vi port_scan.sh
#!/bin/sh
for server in `server-list.txt`
do
#echo $i
nc -zvw3 $server 99
done
Error Output as below:

Code: Select all

Ncat: Version 7.50 ( https://nmap.org/ncat )
": Name or service not known. QUITTING.01.child.domain.com
Ncat: Version 7.50 ( https://nmap.org/ncat )
": Name or service not known. QUITTING.01.child.domain.com
Ncat: Version 7.50 ( https://nmap.org/ncat )
": Name or service not known. QUITTING.03.child.domain.com
Ncat: Version 7.50 ( https://nmap.org/ncat )
": Name or service not known. QUITTING.04.child.domain.com

stevemowbray
Posts: 508
Joined: 2012/06/26 14:20:47

Re: Check whether the port is Open on Multiple Remote CentOS Systems

Post by stevemowbray » 2020/06/04 12:11:35

I would use nmap for this, but the error in your script is that

Code: Select all

for server in `server-list.txt`
should be

Code: Select all

for server in `cat server-list.txt`

rameshreddy
Posts: 2
Joined: 2020/06/03 21:14:41

Re: Check whether the port is Open on Multiple Remote CentOS Systems

Post by rameshreddy » 2020/06/04 14:58:19

Thanks for your reply.

I just tried 'cat' but still i am getting same error.

Code: Select all

for server in `cat server-list.txt`
Regards
Ramesh

User avatar
jlehtone
Posts: 2940
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Check whether the port is Open on Multiple Remote CentOS Systems

Post by jlehtone » 2020/06/04 22:51:56

You should look up "bash loops". Might be something like:

Code: Select all

while read server
do
  echo $server
done < server-list.txt

Post Reply

Return to “CentOS 7 - Networking Support”