icinga2-checks/check_writable.sh

44 lines
793 B
Bash
Raw Normal View History

2024-02-18 00:38:45 -07:00
#!/bin/bash
2024-02-18 00:42:20 -07:00
# 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_writable.sh -p [directory to check]"
exit $STATE_UNKNOWN
2024-02-18 00:38:45 -07:00
fi
# Check if directory exists
2024-02-18 00:42:20 -07:00
if [ ! -d "$path" ]; then
echo "UNKNOWN - $path is not a directory"
2024-02-18 00:38:45 -07:00
exit 3
fi
# Check if directory is writable
2024-02-18 00:42:20 -07:00
if [ -w "$path" ]; then
echo "OK - $path is writable"
exit $STATE_OK
2024-02-18 00:38:45 -07:00
else
2024-02-18 00:42:20 -07:00
echo "CRITICAL - $path is not writable"
2024-02-18 00:38:45 -07:00
exit 2
fi