w4it-for-port-open: Simplified drastically with nc
.
This commit is contained in:
parent
b0b791142b
commit
5ff59030f4
|
@ -13,31 +13,12 @@ usage () {
|
||||||
}
|
}
|
||||||
|
|
||||||
print_not_reachable () {
|
print_not_reachable () {
|
||||||
if [ "$NOT_REACHABLE" = "1" ] ; then
|
|
||||||
echo -n .
|
echo -n .
|
||||||
else
|
|
||||||
echo -n $HOST:$PORT is not reachable
|
|
||||||
NOT_REACHABLE=1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print_up_but_port_closed () {
|
is_port_open () {
|
||||||
if [ "$PORT_CLOSED" = "1" ] ; then
|
$NC -z -w 2 $HOST $PORT 2>&1
|
||||||
echo -n .
|
return $?
|
||||||
else
|
|
||||||
echo -n $HOST is up but port $PORT is closed
|
|
||||||
PORT_CLOSED=1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
port_is_open () {
|
|
||||||
# If tcptraceroute stops working use:
|
|
||||||
# echo | nc -w 2 $HOST $PORT || failed
|
|
||||||
if $NC -z -w 2 $HOST $PORT 2>&1 ; then
|
|
||||||
OPEN=no
|
|
||||||
else
|
|
||||||
OPEN=yes
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ -z "$HOST" ] ; then
|
if [ -z "$HOST" ] ; then
|
||||||
|
@ -51,8 +32,7 @@ if [ -z "$NC" ] ; then
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
port_is_open
|
while ! is_port_open ; do
|
||||||
while [ "$OPEN" = "no" ] ; do
|
print_not_reachable
|
||||||
port_is_open
|
|
||||||
done
|
done
|
||||||
echo
|
echo
|
||||||
|
|
Loading…
Reference in a new issue