diff --git a/check_fs_writable b/check_fs_writable new file mode 100644 index 0000000000000000000000000000000000000000..544ed3d09b5fadafcd53a6e3e43ee6341977c477 --- /dev/null +++ b/check_fs_writable @@ -0,0 +1,96 @@ +#!/usr/bin/env bash +# ====================================================================== +# +# Check filesystem ... is it readonly? +# +# requirements: +# - none +# +# ---------------------------------------------------------------------- +# 2021-03-23 v0.0 <axel.hahn@iml.unibe.ch> +# ====================================================================== + + +. `dirname $0`/inc_pluginfunctions + +dirs2test="/tmp /var/tmp" +out="" + +# ---------------------------------------------------------------------- +# functions +# ---------------------------------------------------------------------- + +function showHelp(){ +cat <<EOF +______________________________________________________________________ + +CHECK_FS_READONLY check if filesystem is readonly - v0.0 + +(c) Institute for Medical Education - Univerity of Bern +Licence: GNU GPL 3 +______________________________________________________________________ + + +SYNTAX: +`basename $0` [directory [more directories]] + +OPTIONS: + + -h or --help show this help. + +PARAMETERS: + + DIRECTORY where to touch a temporary file + +EXAMPLE: +`basename $0` /tmp /root /var/www + +EOF +} +# ---------------------------------------------------------------------- +# MAIN +# ---------------------------------------------------------------------- + +# --- check required tools +# ph.require bc top + + +# --- check param -h +case "$1" in + "--help"|"-h") + showHelp + exit 0 + ;; + *) +esac + +# params are directory names ... if a param was given it overrides the internal default +test $# -gt 0 && dirs2test="$*" + + +# ----- MAKE CHECK + +for mydir in $dirs2test +do + touchfile=$mydir/icinga_touch_testfile__${RANDOM}_${RANDOM} + out="$out + +--- touching something into $mydir + $( touch $touchfile && ls -l $touchfile && rm -f $touchfile 2>&1 )" + if [ $? -ne 0 ]; then + ph.setStatus "critical" + fi +done + + +# ----- OUTPUT + +ph.status "check if filesystem is writable in $dirs2test $out" +#echo "$out" + + +# ----- CLEANUP AND BYE! + +ph.exit + +# ----------------------------------------------------------------------