2012-04-12 22:23:41 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
HOST=$1
|
|
|
|
PORT=$2
|
|
|
|
|
2013-10-10 09:04:36 +00:00
|
|
|
NC=$( which nc )
|
2013-07-02 11:27:11 +00:00
|
|
|
|
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 () {
|
2014-05-03 18:23:22 +00:00
|
|
|
echo -n .
|
2012-04-12 22:23:41 +00:00
|
|
|
}
|
|
|
|
|
2014-05-03 18:23:22 +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
|
2013-10-10 09:04:36 +00:00
|
|
|
if [ -z "$NC" ] ; then
|
|
|
|
echo "Error, 'nc' not installed."
|
2013-07-02 11:27:11 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
2012-04-12 22:23:41 +00:00
|
|
|
|
2014-05-03 18:23:22 +00:00
|
|
|
while ! is_port_open ; do
|
|
|
|
print_not_reachable
|
2012-04-12 22:23:41 +00:00
|
|
|
done
|
|
|
|
echo
|