1

I am using following piece of code on Ubuntu 14.4 to check whether ssh port in my remote machine is open or not

$PROXY_SERVER_IP=192.168.1.40

$LOGGER "Waiting for Proxy-VM ssh port to become active.."
while ! nc -z $PROXY_SERVER_IP 22; do
  sleep 10s
done

Above code works some time but other time it result in infinite loop with following message

This is nc from the netcat-openbsd package. An alternative nc is available
in the netcat-traditional package.
usage: nc [-46DdhklnrStUuvzC] [-i interval] [-P proxy_username] [-p source_port]
      [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]
      [-x proxy_address[:port]] [hostname] [port[s]]

Is there any other way to to know whether port is open or not ?

Jakuje
  • 24,773
  • 12
  • 69
  • 75
Vikram Ranabhatt
  • 7,268
  • 15
  • 70
  • 133
  • Possible duplicate of [How to switch to netcat-traditional in Ubuntu?](http://stackoverflow.com/questions/10065993/how-to-switch-to-netcat-traditional-in-ubuntu) – Jakuje Jan 11 '16 at 09:16
  • `$PROXY_SERVER_IP=192.168.1.40` is a typo. You don't assign values to variables with `$`. That line should be `PROXY_SERVER_IP=192.168.1.40`. That said if that loop ever works it should always work (unless you change `PROXY_SERVER_IP` in the loop somewhere). That said, are you asking *why* you are getting that error or how to switch to a non-openbsd `nc`? Or something else? – Etan Reisner Jan 11 '16 at 12:16

0 Answers0