Skip to content

Commit

Permalink
check_sftp.sh: some debug info
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Vojta <[email protected]>
  • Loading branch information
Jan Vojta committed Jul 1, 2020
1 parent 00a2d3a commit 4d19e2d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions check_sftp.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/bash

#[email protected]
# [email protected]
# [email protected]

host=''
user=''
password=''
timeout=4
timeout=10
port=22

usage(){
Expand All @@ -15,7 +16,7 @@ usage: $0 <options>
-u user
-p password
-P port (defaults to 22)
-t timeout (defaults to 4 seconds)
-t timeout (defaults to 10 seconds)
EOF
exit 3
}
Expand All @@ -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} <<EOF > /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

0 comments on commit 4d19e2d

Please sign in to comment.