Making sure what is configured to mount is mounted

Here is a script that uses some advanced awk commands to check that what is configured to be mounted in /etc/fstab is actually mounted.

#!/bin/ksh
#########################################################################
# fsrootreserve
#HPUX_SCRIPTS=/opt/depots/scripts/system_build/HPUX
#COMMON=/opt/depots/scripts/system_build/COMMON
# Load common environment
. /opt/scripts/env/.scriptenv.linux
# set total variable for reserve blocks
tot=0
        echo “. Checking mount status of all filesystems defined in /etc/fstab”
if [ “$1” = “-y” ];then
CHANGES=1
fi
function fixmount {
  mtname=$1
  mount $mtname
  rc=$?
  if [ $rc -eq 0 ]
  then
      echo ”      pass – ${mpn} is defined in /etc/fstab and currently mounted”
  else
      echo ” FAIL – Remediate manually. The script can not mount ${mpn}.”
#      echo ” I’m sorry Dave I am afraid I can’t do that. HAL-9000.”
  fi
}
# The next line removes blank lines lines beginning with hash and some faux filesystems from the analysis. This is more efficient than piping to grep -v
awk ‘/./ && !/#/ && !/\/tmpfs/ && !/tmpfs/ && !/\/sys/ && !/swap/ && !/\/proc/ { print $2 }’ /etc/fstab  | while read -r mpn
do
echo “checking filesystem $mpn”
mt=$(grep “$mpn ” /proc/mounts |awk ‘!/rootfs/ {print $1}’ | wc -l);
if (($mt != 1 ));then
        if (($CHANGES));then
                fixmount $mpn
        else
                echo ” FAIL      – file system ${mpn} is defined in /etc/fstab and NOT mounted. (-y will attempt to mount).”
        fi
else
                echo ”      pass – ${mpn} is defined in /etc/fstab and currently mounted”
fi
done