39 lines
462 B
Bash
Executable file
39 lines
462 B
Bash
Executable file
#!/bin/bash
|
|
|
|
HOST=$1
|
|
PORT=$2
|
|
|
|
NC=$( which nc )
|
|
|
|
usage () {
|
|
echo "Usage:"
|
|
echo " $0 host [port]"
|
|
echo " port defaults to 22 (ssh)"
|
|
exit 1
|
|
}
|
|
|
|
print_not_reachable () {
|
|
echo -n .
|
|
}
|
|
|
|
is_port_open () {
|
|
$NC -z -w 2 $HOST $PORT 2>&1
|
|
return $?
|
|
}
|
|
|
|
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
|
|
|
|
while ! is_port_open ; do
|
|
print_not_reachable
|
|
done
|
|
echo
|