-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from mmallejac/master
Add non-mandatory sftp option
- Loading branch information
Showing
2 changed files
with
16 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,24 +8,26 @@ | |
# Copyright (c) 2017 Jan Vonde <[email protected]> | ||
# | ||
# | ||
# Usage: ./check_sftpsace.sh -h [host] -u [user] -w [warn] -c [crit] | ||
# Usage: ./check_sftpsace.sh -h [host] -u [user] [ -o sftpOption ] -w [warn] -c [crit] | ||
# | ||
# | ||
# Changelog: | ||
# 2015-12-07: initial Version | ||
# 2017-01-01: remove unused comments, fix WARN and CRIT, add perfdata | ||
# 2020-07-30: add -o option | ||
# | ||
# For more information visit https://github.com/janvonde/check_sftpspace | ||
##### | ||
|
||
|
||
USAGE="Usage: check_sftpsace.sh -h [host] -u [user] -w [warn] -c [crit]" | ||
USAGE="Usage: check_sftpsace.sh -h [host] -u [user] [ -o sftpOption] -w [warn] -c [crit]" | ||
|
||
if [ $# == 8 ]; then | ||
while getopts "h:u:w:c:" OPCOES; do | ||
if [ $# -ge 8 ]; then | ||
while getopts "h:u:o::w:c:" OPCOES; do | ||
case $OPCOES in | ||
h ) SFTPHOST=$OPTARG;; | ||
u ) SFTPUSER=$OPTARG;; | ||
o ) SFTPOPTN=$OPTARG;; | ||
w ) WARN=$OPTARG;; | ||
c ) CRIT=$OPTARG;; | ||
? ) echo $USAGE | ||
|
@@ -42,10 +44,12 @@ fi | |
## error handling | ||
type -P sftp &>/dev/null || { echo "ERROR: sftp is required but seems not to be installed. Aborting." >&2; exit 1; } | ||
|
||
## sftp extra opt | ||
[ -z $SFTPOPTN ] && SFTPOPTN="port=22" | ||
|
||
|
||
## get info and store | ||
RESULT=$(echo "df -h" | sftp ${SFTPUSER}@${SFTPHOST} 2>&1 | tail -1 | column -t) | ||
RESULT=$(echo "df -h" | sftp -o $SFTPOPTN ${SFTPUSER}@${SFTPHOST} 2>&1 | tail -1 | column -t) | ||
read TOTAL USED AVAILABLE ROOT PERCENT <<< $RESULT | ||
PERCENT=$(expr 100 - ${PERCENT/\%/}) | ||
|
||
|
@@ -63,6 +67,6 @@ if [ ${PERCENT} -lt ${WARN} ]; then | |
fi | ||
|
||
|
||
echo "OK - ${AVAILABLE} free space: (${USED} out of ${TOTAL} or ${PERCENT}% used) |sftp_disk_usage=${USED};${WARN};${CRIT};0;${TOTAL}" | ||
echo "OK - ${AVAILABLE} free space: (${USED} out of ${TOTAL} or ${PERCENT}% free) |sftp_disk_usage=${USED};${WARN};${CRIT};0;${TOTAL}" | ||
exit 0 | ||
|