33 lines
458 B
Text
33 lines
458 B
Text
|
#!/usr/bin/env bash
|
||
|
|
||
|
set -eu
|
||
|
script_name=$0
|
||
|
|
||
|
die() {
|
||
|
echo >&2 "$@"
|
||
|
exit 1
|
||
|
}
|
||
|
|
||
|
about() {
|
||
|
die "usage: $script_name <port_number>"
|
||
|
}
|
||
|
|
||
|
[ $# -lt 1 ] && about
|
||
|
|
||
|
port_number=$1
|
||
|
|
||
|
for _ in $(seq 40); do
|
||
|
nc -z localhost "$port_number" >/dev/null 2>&1 && exit 0
|
||
|
sleep .05
|
||
|
done
|
||
|
|
||
|
# send to &3 if open
|
||
|
if { true >&3; } 2>/dev/null; then
|
||
|
echo "Can't connect to port $port_number" >&3
|
||
|
else
|
||
|
echo "Can't connect to port $port_number" >&2
|
||
|
fi
|
||
|
|
||
|
exit 1
|
||
|
|