[Shell Script] Check SFTP Availability With shell script
This article demonstrates how to use the community-distributed plugin check_sftp_avail in Nagios.
If you have this issue :
[nagios@supervision plugins]# ./check_sftp -p 22 -H 192.168.0.1
WARNING: Host key verification failed - unable to authenticate server
Solve it by add the RSA Fingerprint :
[nagios@supervision plugins]# sftp maintenance@192.168.0.1
Connecting to 192.168.90.126...
The authenticity of host '192.168.90.126 (192.168.90.126)' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:x:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.1' (RSA) to the list of known hosts.
#!/bin/sh
#
# Usage: ./check_sftp_avail [ -p ] -H
#
# Paths to commands used in this script. These
# may have to be modified to match your system setup.
SFTP="/usr/bin/sftp"
RM="/bin/rm"
PROGNAME=`/usr/bin/basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION="1.0.0"
. $PROGPATH/utils.sh
print_usage() {
echo "Usage: $PROGNAME [ -p port ] -H host"
echo "Usage: $PROGNAME --help"
echo "Usage: $PROGNAME --version"
}
print_help() {
print_revision $PROGNAME $REVISION
echo ""
print_usage
echo ""
echo "sftp service availability plugin for Nagios"
echo ""
support
}
# Make sure the correct number of command line
# arguments have been supplied
if [ $# -lt 1 ]; then
print_usage
exit $STATE_UNKNOWN
fi
port=115 # Default for sftp
exitstatus=$STATE_WARNING #default
while test -n "$1"; do
case "$1" in
--help)
print_help
exit $STATE_OK
;;
-h)
print_help
exit $STATE_OK
;;
--version)
print_revision $PROGNAME $REVISION
exit $STATE_OK
;;
-V)
print_revision $PROGNAME $REVISION
exit $STATE_OK
;;
--hostname)
box=$2
shift
;;
-H)
box=$2
shift
;;
--port)
port=$2
shift
;;
-p)
port=$2
shift
;;
*)
echo "Unknown argument: $1"
print_usage
exit $STATE_UNKNOWN
;;
esac
shift
done
# Make sure a hostname and port have been specified
if [ -z "$box" -o -z "$port" ]; then
print_usage
exit $STATE_UNKNOWN
fi
tempfile=/tmp/check_sftp-$box.tmp
exitstatus=$STATE_UNKNOWN
$SFTP -b - $box &>$tempfile <<EOF
EOF
if [ ! -e "$tempfile" ]; then
stdio="No sftp output found" && $RM -f $tempfile && echo $stdio && exit $STATE_UNKNOWN;
fi
status=`tail -2 $tempfile`
if [ "`grep -c 'Permission denied' $tempfile`" == "1" ]; then
exit=$STATE_OK && stdio="OK: service available"
elif [ "`grep -c 'Host key verification failed' $tempfile`" == "1" ]; then
exit=$STATE_WARNING && stdio="WARNING: Host key verification failed - unable to authenticate server"
else
exit=$STATE_CRITICAL && stdio="CRITICAL: service unavailable"
fi
$RM -f $tempfile
echo $stdio
exit $exit
Leave [Shell Script] Check SFTP Availability With shell script to:
Read more #dev posts
Best Posts From capslock
We have not curated any of capslock's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From capslock
- I like beer!
- Hive? What is it?
- 방갑습니다 하이브!
- ????
- Windows 7에 Python Steem 라이브러리 설치 성공(pycrypto 오류 해결)
- 이거 스티밋에 얼마만인지...
- 제주 선녀와 나무꾼 테마공원
- 제주도 성산일출봉 인근 흑돼지 맛집 광치기 정육식당
- [Oracle] 오라클 SQL에서 정규식 사용하여 문자열 잘라내기(10g 이상)
- [Shell Script] check physical memory monitoring shell script
- [Shell Script] This script connects to a site via curl and searches for a string in the web page.
- [Shell Script] Check SFTP Availability With shell script
- 명동성당에 다녀왔습니다.
- [제주도 필수코스] 성산항에서 우도를 가봅시다!!!
- [Shell Script] process monitoring script, web/was server monitoring script(using curl)
- When & How to Wash Your Hands - 언제 손을 씻어야 할까???
- 제주도 성산일출봉 drone으로 촬영한 영상입니다. [Jeju Island, 濟州島]
- 제주도 서귀포시 산방산 드론사진 구경하세요 [Jeju Island, 濟州島]
- 제주도 가면 꼭 가봐야 할 용눈이 오름
- 너무하네