f6a34e1200
w4it-for-port-open: -q (quiet) implemented.
58 lines
683 B
Bash
Executable file
58 lines
683 B
Bash
Executable file
#!/bin/bash
|
|
|
|
QUIET=false
|
|
|
|
while getopts ":q" opt; do
|
|
case $opt in
|
|
q)
|
|
QUIET=true
|
|
shift
|
|
;;
|
|
\?)
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
;;
|
|
esac
|
|
done
|
|
|
|
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 () {
|
|
if $QUIET; then
|
|
true skip
|
|
else
|
|
echo -n .
|
|
fi
|
|
}
|
|
|
|
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
|
|
sleep 1
|
|
print_not_reachable
|
|
done
|
|
echo
|