diff --git a/check_not_writable.sh b/check_not_writable.sh index 1cc756a..52481d1 100755 --- a/check_not_writable.sh +++ b/check_not_writable.sh @@ -1,23 +1,43 @@ #!/bin/bash -# Check if argument is provided -if [ $# -eq 0 ]; then - echo "No arguments provided" - echo "./check_writable.sh [path to directory to test]" - exit 3 +# 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 " + 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 "$1" ]; then - echo "UNKNOWN - $1 is not a directory" +if [ ! -d "$path" ]; then + echo "UNKNOWN - $path is not a directory" exit 3 fi -# Check if directory is not writable -if [ ! -w "$1" ]; then - echo "OK - $1 is not writable" - exit 0 +# Check if directory is writable +if [ ! -w "$path" ]; then + echo "OK - $path is not writable" + exit $STATE_OK else - echo "CRITICAL - $1 is writable" + echo "CRITICAL - $path is writable" exit 2 fi diff --git a/check_writable.sh b/check_writable.sh index 880b009..1ee4ac3 100755 --- a/check_writable.sh +++ b/check_writable.sh @@ -1,23 +1,43 @@ #!/bin/bash -# Check if argument is provided -if [ $# -eq 0 ]; then - echo "No arguments provided" - echo "./check_writable.sh [path to directory to test]" - exit 3 +# 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 " + 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 fi # Check if directory exists -if [ ! -d "$1" ]; then - echo "UNKNOWN - $1 is not a directory" +if [ ! -d "$path" ]; then + echo "UNKNOWN - $path is not a directory" exit 3 fi # Check if directory is writable -if [ -w "$1" ]; then - echo "OK - $1 is writable" - exit 0 +if [ -w "$path" ]; then + echo "OK - $path is writable" + exit $STATE_OK else - echo "CRITICAL - $1 is not writable" + echo "CRITICAL - $path is not writable" exit 2 fi