diff --git a/w4it-for-port-open/w4it-for-port-open b/w4it-for-port-open/w4it-for-port-open index f6c0463..7ccf36a 100755 --- a/w4it-for-port-open/w4it-for-port-open +++ b/w4it-for-port-open/w4it-for-port-open @@ -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)" - exit 1 + ( + 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 diff --git a/wssh/wssh b/wssh/wssh index d0d09b7..bc57c72 100755 --- a/wssh/wssh +++ b/wssh/wssh @@ -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;