From 4d19e2dd9bc1444de27cd6833457d2b458762c5b Mon Sep 17 00:00:00 2001 From: Jan Vojta Date: Wed, 1 Jul 2020 10:33:47 +0200 Subject: [PATCH] check_sftp.sh: some debug info Signed-off-by: Jan Vojta --- check_sftp.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/check_sftp.sh b/check_sftp.sh index c3d0b8a..51424e5 100644 --- a/check_sftp.sh +++ b/check_sftp.sh @@ -1,11 +1,12 @@ #!/bin/bash -#honza@inuits.eu +# honza@inuits.eu +# yenda@inuits.eu host='' user='' password='' -timeout=4 +timeout=10 port=22 usage(){ @@ -15,7 +16,7 @@ usage: $0 -u user -p password -P port (defaults to 22) - -t timeout (defaults to 4 seconds) + -t timeout (defaults to 10 seconds) EOF exit 3 } @@ -39,13 +40,17 @@ fi which lftp &>/dev/null || { echo 'You need to have lftp installed.'; exit 3; } -timeout $timeout lftp -u ${user},${password} sftp://${host}:${port} < /dev/null -ls -bye -EOF +# 'set net:max-retries 1' - 0 set unlimited, 1 - no retries +# 'set net:timeout ${timeout}' - sets the network protocol timeout. +# 'set net:reconnect-interval-base 5' - sets the base minimal time between reconnects + +OUT=$(lftp -u "${user},${password}" sftp://$host:$port -e "set net:timeout ${timeout};set net:max-retries 1;set net:reconnect-interval-base 5;ls;bye" 2>&1) if [[ $? -ne 0 ]]; then - echo "Unable to connect to connect to ${host}"; exit 2; + echo "Unable to connect to connect to ${host}" + echo $OUT + exit 2 else - echo "Successfully connected to ${host}"; exit 0; + echo "Successfully connected to ${host}" + exit 0 fi