Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
check_smb_file_simple
1.0
2013-03-28
- Nagios 3.x
- Nagios XI
GPL
45131
File | Description |
---|---|
check_smb_file | Put on your nagios plugins dir, and add it on Nagios configuration. |
Meet The New Nagios Core Services Platform
Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.
Monitoring Made Magically Better
- Nagios Core on Overdrive
- Powerful Monitoring Dashboards
- Time-Saving Configuration Wizards
- Open Source Powered Monitoring On Steroids
- And So Much More!
You can use is to test if a file exists on a windows domain.
Usage:
$PROGNAME -H -W -s -f -u -p -S -E
$PROGNAME --help
$PROGNAME --version
Simple script to test a samba share.
You can use is to test if a file exists on a windows domain.
Use anonymous login if user name is not supplied.
IT NEEDS SMBCLIENT PACKET TO WORK!
Usage:
$PROGNAME -H -W -s -f -u -p -S -E
$PROGNAME --help
$PROGNAME --version
Put on your nagios plugins dir, and add it on Nagios configuration.
You can use is to test if a file exists on a windows domain.
Use anonymous login if user name is not supplied.
IT NEEDS SMBCLIENT PACKET TO WORK!
Usage:
$PROGNAME -H
$PROGNAME --help
$PROGNAME --version
Put on your nagios plugins dir, and add it on Nagios configuration.
Reviews (2)
byJVD, December 23, 2019
I also want to check a sub directory in a share, so i added a sub directory parameter (-d), see the code:
---------------------------------
[root@localhost ~]# cat /usr/local/nagios/libexec/check_smb_file.sh
#!/bin/sh
# Check for file on SMB with nagios
# Cristian Barreto 2013-03-27
REVISION=1.0
PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
. $PROGPATH/utils.sh
usage () {
echo "\
Nagios plugin to check for SAMBA File. Use anonymous login if user name is not supplied.
IT NEEDS SMBCLIENT PACKET TO WORK!
Usage:
$PROGNAME -H -W -s -f -u -p -S -E
$PROGNAME --help
$PROGNAME --version
"
}
help () {
print_revision $PROGNAME $REVISION
echo; usage; echo; support
}
#print help
if [ $# -lt 3 ]; then
usage
exit $STATE_UNKNOWN
fi
user="guest"
pasword=""
while test -n "$1"; do
case "$1" in
--help | -h)
help
exit $STATE_OK;;
--version | -V)
print_revision $PROGNAME $REVISION
exit $STATE_OK;;
-H)
shift
host="$1";;
-W)
shift
workgroup="$1";;
-s)
shift
sharePathToTest="$1";;
-d)
shift
directoryToTest="$1";;
-f)
shift
fileToTest="$1";;
-u)
shift
user="$1";;
-p)
shift
password="$1";;
-S)
shift
onSuccessMessage="$1";;
-E)
shift
onErrorMessage="$1";;
*)
usage; exit $STATE_UNKNOWN;;
esac
shift
done
onSuccessMessage="OK: File exists!"
onErrorMessage="ERROR: File \"//"$host""$sharePathToTest"$fileToTest\" does not exists."
if [ "$fileToTest" == "" ]; then
echo "ERROR: You need to specify a file to test using -f parameter."
exit $STATE_UNKNOWN
fi
if [ "$directoryToTest" == "" ]; then
echo "directoryToTest = empty, do not add a sub directory after the share (and before the filename)"
fileToTest="$fileToTest"
else
echo "directoryToTest = Filled, add a sub directory after the share (and before the filename)"
fileToTest = "$directoryToTest/$fileToTest"
fi
smbclient //"$host""$sharePathToTest" -U "$user"%"$password" -W "$workgroup" -c "get "$directoryToTest/$fileToTest" /tmp/"$fileToTest""
if [ -f /tmp/"$fileToTest" ]; then
rm -f /tmp/"$fileToTest"
echo $onSuccessMessage
exit $STATE_OK
else
echo $onErrorMessage
exit $STATE_CRITICAL
fi
---------------------------------
[root@localhost ~]# cat /usr/local/nagios/libexec/check_smb_file.sh
#!/bin/sh
# Check for file on SMB with nagios
# Cristian Barreto 2013-03-27
REVISION=1.0
PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
. $PROGPATH/utils.sh
usage () {
echo "\
Nagios plugin to check for SAMBA File. Use anonymous login if user name is not supplied.
IT NEEDS SMBCLIENT PACKET TO WORK!
Usage:
$PROGNAME -H -W -s -f -u -p -S -E
$PROGNAME --help
$PROGNAME --version
"
}
help () {
print_revision $PROGNAME $REVISION
echo; usage; echo; support
}
#print help
if [ $# -lt 3 ]; then
usage
exit $STATE_UNKNOWN
fi
user="guest"
pasword=""
while test -n "$1"; do
case "$1" in
--help | -h)
help
exit $STATE_OK;;
--version | -V)
print_revision $PROGNAME $REVISION
exit $STATE_OK;;
-H)
shift
host="$1";;
-W)
shift
workgroup="$1";;
-s)
shift
sharePathToTest="$1";;
-d)
shift
directoryToTest="$1";;
-f)
shift
fileToTest="$1";;
-u)
shift
user="$1";;
-p)
shift
password="$1";;
-S)
shift
onSuccessMessage="$1";;
-E)
shift
onErrorMessage="$1";;
*)
usage; exit $STATE_UNKNOWN;;
esac
shift
done
onSuccessMessage="OK: File exists!"
onErrorMessage="ERROR: File \"//"$host""$sharePathToTest"$fileToTest\" does not exists."
if [ "$fileToTest" == "" ]; then
echo "ERROR: You need to specify a file to test using -f parameter."
exit $STATE_UNKNOWN
fi
if [ "$directoryToTest" == "" ]; then
echo "directoryToTest = empty, do not add a sub directory after the share (and before the filename)"
fileToTest="$fileToTest"
else
echo "directoryToTest = Filled, add a sub directory after the share (and before the filename)"
fileToTest = "$directoryToTest/$fileToTest"
fi
smbclient //"$host""$sharePathToTest" -U "$user"%"$password" -W "$workgroup" -c "get "$directoryToTest/$fileToTest" /tmp/"$fileToTest""
if [ -f /tmp/"$fileToTest" ]; then
rm -f /tmp/"$fileToTest"
echo $onSuccessMessage
exit $STATE_OK
else
echo $onErrorMessage
exit $STATE_CRITICAL
fi
Thanks for the great script. Made the following updates to deal with files in subdirectories:
$ diff check_smb_file check_smb_file-orig
18c18
$PROGNAME -H -W -s -f -u -p -S -E
57,59d56
";;
82c79
onErrorMessage="ERROR: File \"//"$host""$sharePathToTest"$fileToTest\" does not exists."
89c86
smbclient //"$host""$sharePathToTest" -U "$user"%"$password" -W "$workgroup" -c "get '$fileToTest' /tmp/"$fileToTest""
92c89
rm -f /tmp/"$fileToTest"
$ diff check_smb_file check_smb_file-orig
18c18
$PROGNAME -H -W -s -f -u -p -S -E
57,59d56
";;
82c79
onErrorMessage="ERROR: File \"//"$host""$sharePathToTest"$fileToTest\" does not exists."
89c86
smbclient //"$host""$sharePathToTest" -U "$user"%"$password" -W "$workgroup" -c "get '$fileToTest' /tmp/"$fileToTest""
92c89
rm -f /tmp/"$fileToTest"