From d30b621ef92255206afdf47e8036195c59a813b8 Mon Sep 17 00:00:00 2001 From: Ralf Zerres Date: Sat, 29 Dec 2018 04:33:27 +0100 Subject: [PATCH] dsnap-sync: check if remote host is reachable - use nc if available - abort execution, if remote host can't be reached via ssh Signed-off-by: Ralf Zerres --- bin/dsnap-sync | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/bin/dsnap-sync b/bin/dsnap-sync index 62b09c2..d678499 100755 --- a/bin/dsnap-sync +++ b/bin/dsnap-sync @@ -118,15 +118,10 @@ check_prerequisites () { which notify-send >/dev/null 2>&1 && { donotify=1; } which pv >/dev/null 2>&1 && { do_pv_cmd=1; } which tape-admin >/dev/null 2>&1 && { tape_admin_cmd=1; } + which nc >/dev/null 2>&1 && { nc_cmd=1; } if [ $(id -u) -ne 0 ] ; then printf "$progname: must be run as root\n" ; exit 1 ; fi - if [ -n "$remote" ]; then - $ssh which sh >/dev/null 2>&1 || \ - { printf "'remote shell' is not working!\n \ - Please correct your public authentication and try again.\n" && exit 1; } - fi - if [ ! -r "$SNAPPER_CONFIG" ]; then die "$progname: $SNAPPER_CONFIG does not exist." fi @@ -1186,6 +1181,16 @@ parse_params () { if [ ! -z "$port" ]; then ssh="$ssh -p $port" scp="$scp -P $port" + else + port=22 + fi + if [ $nc_cmd ]; then + nc -w 3 -z $remote $port > /dev/null || \ + die "Can't connect to remote host." + else + $ssh which sh >/dev/null 2>&1 || \ + { printf "'remote shell' is not working!\n \ + Please correct your public authentication and try again.\n" && exit 1; } fi fi