icinga2-checks/check_not_writable.sh

44 lines
799 B
Bash
Executable File

#!/bin/bash
# Default exit code for Nagios
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
# Parse command line options
while getopts "p:" OPTION
do
case $OPTION in
p)
path=$OPTARG
;;
*)
echo "Usage: $0 -p <path>"
exit $STATE_UNKNOWN
;;
esac
done
# Check if path is set
if [ -z "$path" ]; then
echo "No path specified"
echo "./check_not_writable.sh -p [directory to check]"
exit $STATE_UNKNOWN
fi
# Check if directory exists
if [ ! -d "$path" ]; then
echo "UNKNOWN - $path is not a directory"
exit 3
fi
# Check if directory is writable
if [ ! -w "$path" ]; then
echo "OK - $path is not writable"
exit $STATE_OK
else
echo "CRITICAL - $path is writable"
exit 2
fi