[root@db-gitlab-harbor ~]# cat /tmp/ports.txt 192.168.0.1 22 127.0.0.1 22 127.0.0.1 222 [root@db-gitlab-harbor ~]# [root@db-gitlab-harbor ~]# cat telnet.sh #! /bin/bash cat /tmp/ports.txt |while read line do nc -z -w 10 $line >/dev/null 2>&1 if [ $? -eq 0 ] then echo $line:ok else echo $line:false fi done [root@db-gitlab-harbor ~]#