As a side note: this is just a thread part of my
main thread which is destinated at securing debian!
I'd like to thank unSpawn for this script. I have just adjusted it (made it lame), so credits go to unspawn:
Code:
----------------------------------------------------------------------
created check_mount script [ /usr/local/sbin/check_mounts.sh ]
----------------------------------------------------------------------
#!/bin/sh
# --------------------------------------------------------------------
# purpose: check mounted partitions,
# log if not mounted + mount and notify admins
# args: none
# deps: bash, GNU utils, logger, /proc, /etc/fstab
# --------------------------------------------------------------------
# --------------------------------------------------------------------
# configuration
# --------------------------------------------------------------------
FSTAB_EXCL="(^#|noauto|none|user)"
PROGNAME=$(basename $0)
export PATH="/bin:/sbin:/usr/bin:/usr/sbin"
# --------------------------------------------------------------------
# --------------------------------------------------------------------
# configure destination address for emails (admins)
# --------------------------------------------------------------------
if [ -f /etc/default/suk_scripts ]; then
. /etc/default/suk_scripts;
else
ROOTMAIL="root@`hostname --fqdn`"
fi
# --------------------------------------------------------------------
# --------------------------------------------------------------------
# functions
# --------------------------------------------------------------------
function err_descr() {
case "$?" in
0) err_rv="OK"
;;
1) err_rv="FAILED"
;;
*) err_rv="$?"
;;
esac;
}
function log() {
/usr/bin/logger -i -p kern.warn -t ${PROGNAME} "$@";
}
function log_mail() {
mail -s "$@" ${ROOTMAIL} ; log "$@";
}
# --------------------------------------------------------------------
# --------------------------------------------------------------------
# check mounts
# --------------------------------------------------------------------
if [ ! -f /proc/mounts ]; then
log "WARN: /proc wasn't mounted!"
mount -t proc proc /proc; err_descr
err_descr
log_mail "WARN: mounted /proc (${err_rv})"
fi
egrep /etc/fstab -ve "${FSTAB_EXCL}" | while read i; do i=( ${i} )
# empty ?
case ${#i[0]} in
0) log_mail "FATAL: I shouldn't have read ${i[@]} !"
eval ${i[0]:=ERROR} 2>/dev/null
;;
esac
# select device
case ${i[0]} in
/dev*)
dev=( ${i[0]} ${i[1]} )
;;
*)
dev=( UNKNOWN UNKNOWN )
;;
esac
# munge rootfs
case "${#dev[1]}" in
1) case "${dev[1]}" in
/) dev[0]=/dev/root
;;
esac
;;
esac
# check mounts
grep /proc/mounts -e ${dev[0]} &> /dev/null
case "$?" in
1) case ${dev[0]} in
/dev/root)
/bin/true
;;
UNKNOWN)
;;
*)
log "WARN: ${dev[1]} isn't mounted"
mount ${dev[1]}; err_descr
log_mail "INFO: mounted ${dev[1]}"
;;
esac
;;
esac
done
# --------------------------------------------------------------------
exit $?
----------------------------------------------------------------------
----------------------------------------------------------------------
added check_mounts to cron [ /etc/cron.d/check_mounts ]
----------------------------------------------------------------------
*/15 * * * * root /usr/local/sbin/check_mounts.sh
----------------------------------------------------------------------