tangetools/w4it-for-port-open/w4it-for-port-open

39 lines
462 B
Plaintext
Raw Normal View History

2012-04-12 22:23:41 +00:00
#!/bin/bash
HOST=$1
PORT=$2
NC=$( which nc )
2012-04-12 22:23:41 +00:00
usage () {
echo "Usage:"
echo " $0 host [port]"
echo " port defaults to 22 (ssh)"
exit 1
}
print_not_reachable () {
echo -n .
2012-04-12 22:23:41 +00:00
}
is_port_open () {
$NC -z -w 2 $HOST $PORT 2>&1
return $?
2012-04-12 22:23:41 +00:00
}
if [ -z "$HOST" ] ; then
usage
fi
if [ -z "$PORT" ] ; then
PORT=22
fi
if [ -z "$NC" ] ; then
echo "Error, 'nc' not installed."
exit 2
fi
2012-04-12 22:23:41 +00:00
while ! is_port_open ; do
print_not_reachable
2012-04-12 22:23:41 +00:00
done
echo