#!/usr/bin/env bash # ====================================================================== # # Check filesystem ... is it readonly? # # requirements: # - none # # ---------------------------------------------------------------------- # 2021-03-23 v0.0 <axel.hahn@iml.unibe.ch> # 2023-07-27 v1.2 <axel.hahn@unibe.ch> shell fixes; update help page # ====================================================================== . $( dirname $0 )/inc_pluginfunctions self_APPVERSION=1.2 dirs2test="/tmp /var/tmp" out="" # ---------------------------------------------------------------------- # functions # ---------------------------------------------------------------------- function showHelp(){ local _self; _self=$(basename $0) cat <<EOF $( ph.showImlHelpHeader ) Check if a filesystem is readonly in given directories. In each of the given directories a random file will be touched. The response is critical of one of the directory is not writable for the icinga client user. SYNTAX: $_self [directory [more directories]] OPTIONS: -h or --help show this help. PARAMETERS: DIRECTORY where to touch a temporary file default directories: $dirs2test EXAMPLE: $_self /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} if ! out="$out --- touching something into $mydir $( touch $touchfile 2>&1 && ls -l $touchfile && rm -f $touchfile )" then ph.setStatus "critical" fi done # ----- OUTPUT ph.status "check if filesystem is writable in $dirs2test $out" # ----- CLEANUP AND BYE! ph.exit # ----------------------------------------------------------------------