fix writable

This commit is contained in:
Cyberes 2024-02-18 00:42:20 -07:00
parent 406086a119
commit f9c8f623dc
2 changed files with 63 additions and 23 deletions

View File

@ -1,23 +1,43 @@
#!/bin/bash #!/bin/bash
# Check if argument is provided # Default exit code for Nagios
if [ $# -eq 0 ]; then STATE_OK=0
echo "No arguments provided" STATE_WARNING=1
echo "./check_writable.sh [path to directory to test]" STATE_CRITICAL=2
exit 3 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 fi
# Check if directory exists # Check if directory exists
if [ ! -d "$1" ]; then if [ ! -d "$path" ]; then
echo "UNKNOWN - $1 is not a directory" echo "UNKNOWN - $path is not a directory"
exit 3 exit 3
fi fi
# Check if directory is not writable # Check if directory is writable
if [ ! -w "$1" ]; then if [ ! -w "$path" ]; then
echo "OK - $1 is not writable" echo "OK - $path is not writable"
exit 0 exit $STATE_OK
else else
echo "CRITICAL - $1 is writable" echo "CRITICAL - $path is writable"
exit 2 exit 2
fi fi

View File

@ -1,23 +1,43 @@
#!/bin/bash #!/bin/bash
# Check if argument is provided # Default exit code for Nagios
if [ $# -eq 0 ]; then STATE_OK=0
echo "No arguments provided" STATE_WARNING=1
echo "./check_writable.sh [path to directory to test]" STATE_CRITICAL=2
exit 3 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
fi fi
# Check if directory exists # Check if directory exists
if [ ! -d "$1" ]; then if [ ! -d "$path" ]; then
echo "UNKNOWN - $1 is not a directory" echo "UNKNOWN - $path is not a directory"
exit 3 exit 3
fi fi
# Check if directory is writable # Check if directory is writable
if [ -w "$1" ]; then if [ -w "$path" ]; then
echo "OK - $1 is writable" echo "OK - $path is writable"
exit 0 exit $STATE_OK
else else
echo "CRITICAL - $1 is not writable" echo "CRITICAL - $path is not writable"
exit 2 exit 2
fi fi