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

View file

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