wssh: Connection status on stderr.

This commit is contained in:
Ole Tange 2020-09-19 11:07:39 +02:00
parent e239a5e302
commit d0da0206ea
2 changed files with 19 additions and 21 deletions

View file

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
QUIET=false quiet=false
while getopts ":q" opt; do while getopts ":q" opt; do
case $opt in case $opt in
q) q)
QUIET=true quiet=true
shift shift
;; ;;
\?) \?)
@ -14,38 +14,36 @@ while getopts ":q" opt; do
esac esac
done done
HOST=$1 host=$1
PORT=$2 port=$2
NC=$( which nc ) nc=$( which nc )
usage () { usage () {
echo "Usage:" (
echo " $0 host [port]" echo "Usage:"
echo " port defaults to 22 (ssh)" echo " $0 host [port]"
exit 1 echo " port defaults to 22 (ssh)"
) >&2
exit 1
} }
print_not_reachable () { print_not_reachable () {
if $QUIET; then $quiet || echo -n . >&2
true skip
else
echo -n .
fi
} }
is_port_open () { is_port_open () {
$NC -z -w 2 $HOST $PORT 2>&1 $nc -z -w 2 $host $port >&2
return $? return $?
} }
if [ -z "$HOST" ] ; then if [ -z "$host" ] ; then
usage usage
fi fi
if [ -z "$PORT" ] ; then if [ -z "$port" ] ; then
PORT=22 port=22
fi fi
if [ -z "$NC" ] ; then if [ -z "$nc" ] ; then
echo "Error, 'nc' not installed." echo "Error, 'nc' not installed."
exit 2 exit 2
fi fi
@ -54,4 +52,4 @@ while ! is_port_open ; do
sleep 1 sleep 1
print_not_reachable print_not_reachable
done done
echo echo >&2

View file

@ -72,7 +72,7 @@ get_options_from_array(\@ARGV,[]);
my $host = shift @ARGV; my $host = shift @ARGV;
@ARGV=("ssh",@argv); @ARGV=("ssh",@argv);
$host =~ s/.*\@//; $host =~ s/.*\@//;
print $host; print STDERR $host;
system("w4it-for-port-open $host 22"); system("w4it-for-port-open $host 22");
exec @ARGV; exec @ARGV;