-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: honza <[email protected]>
- Loading branch information
honza
committed
Dec 10, 2019
1 parent
b3ff4d5
commit 00a2d3a
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
|
||
#[email protected] | ||
|
||
host='' | ||
user='' | ||
password='' | ||
timeout=4 | ||
port=22 | ||
|
||
usage(){ | ||
cat <<EOF | ||
usage: $0 <options> | ||
-h host | ||
-u user | ||
-p password | ||
-P port (defaults to 22) | ||
-t timeout (defaults to 4 seconds) | ||
EOF | ||
exit 3 | ||
} | ||
|
||
while getopts 'u:p:h:P:t:' OPTION | ||
do | ||
case $OPTION in | ||
|
||
u) user=$OPTARG;; | ||
p) password=$OPTARG;; | ||
h) host=$OPTARG;; | ||
P) port=$OPTARG;; | ||
t) timeout=$OPTARG;; | ||
*) usage;; | ||
esac | ||
done | ||
|
||
if [[ -z $user ]] || [[ -z $password ]] || [[ -z $host ]]; then | ||
usage | ||
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 | ||
|
||
if [[ $? -ne 0 ]]; then | ||
echo "Unable to connect to connect to ${host}"; exit 2; | ||
else | ||
echo "Successfully connected to ${host}"; exit 0; | ||
fi |