ciphermethod.com

rocheck.sh

by on Nov.17, 2011, under Scripts

#!/bin/sh

# Created 20111107 – Jamey Hopkins
# Nagios script to check base file paths for a possible read only filesystem condition

USER=`whoami`
F=”rocheck.safetodelete”
# sets paths to test
PATHS=`df -P -l -x tmpfs -x vmhgfs -x iso9660 | column -t | awk ‘{ print $6 }’ | grep -v “Mounted” | xargs echo`
# define specific paths
#PATHS=”/ /home /opt /tmp /usr /var”

if [ “$USER” != “root” ]
then
   echo “Run $0 command as root”
   exit
fi

for P in `echo $PATHS`
do
   [ “$P” = “/” ] && P=”” # don’t process a double slash
   PF=”$P/$F”
   touch $PF >/dev/null 2>&1
   if [ “$?” != “0” ]
   then
      [ “$P” = “” ] && P=”/” # add slash back if it was ro
      FAIL=”$FAIL $P” # add P to string of failed paths
   fi
   [ -e $PF ] && rm $PF >/dev/null 2>&1
done

if [ “$FAIL” != “” ]
then
   # return an error 2 status with a list of directories that failed the touch test
   echo “Read Only:$FAIL”
   exit 2
fi

# return a good status with the list of directories that were checked
echo “Good: $PATHS”
exit 0

No comments for this entry yet...

Leave a Reply

You must be logged in to post a comment.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

But Wait, There's More!

A few highly recommended friends...