START_TIME=$(date +%s)
END_TIME=$(date +%s)
ELAPSED_TIME=$(($END_TIME - $START_TIME))
TIMEOUT=30


STATUS=false
while [ $STATUS = false ] && [ $ELAPSED_TIME -lt $TIMEOUT ]
do
  nc -vz <IP_ADDRESS> <PORT_NUMBER> > /dev/null 2>%1
  retval=$?
  if [ $retval -eq 1 ]; then
    STATUS=false
  else
    STATUS=true
  fi
  END_TIME=$(date +%s)
  ELAPSED_TIME=$(($END_TIME - $START_TIME))
  echo "Time: $ELAPSED_TIME"
  sleep 1
done