Skip to content

Commit

Permalink
check_sftp.sh
Browse files Browse the repository at this point in the history
Signed-off-by: honza <[email protected]>
  • Loading branch information
honza committed Dec 10, 2019
1 parent b3ff4d5 commit 00a2d3a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ An example Vagrant project has been included to get you started right away.
<td><a href="https://github.com/anordby">anordby</a></td>
<td></td>
</tr>
<tr>
<td>check_sftp.sh</td>
<td><a href="https://github.com/honzatlusty">Jan Tlusty</a></td>
<td><a href="https://github.com/honzatlusty/nagios-sftp">upstream</a></td>
</tr>
</table>

### Contributions
Expand Down
1 change: 1 addition & 0 deletions build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@ check_sentry-events.sh 1.0
check_vault.sh 1.2
check_consul.py 1.0
check_ftp.pl 1.0
check_sftp.sh 1.0
# vim: set ts=2 sw=2 et : #
51 changes: 51 additions & 0 deletions check_sftp.sh
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

0 comments on commit 00a2d3a

Please sign in to comment.