Page 1 of 1

Check whether the port is Open on Multiple Remote CentOS Systems

Posted: 2020/06/03 21:26:15
by rameshreddy
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

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

Posted: 2020/06/04 12:11:35
by stevemowbray
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`

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

Posted: 2020/06/04 14:58:19
by rameshreddy
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

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

Posted: 2020/06/04 22:51:56
by jlehtone
You should look up "bash loops". Might be something like:

Code: Select all

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