LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-25-2003, 05:48 AM   #1
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
SCRIPT: check if auto-mount mount-points are still mounted


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
----------------------------------------------------------------------
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mount problem - device already mounted or mount point busy zahoo Linux - General 7 08-28-2009 05:02 PM
Auto mount. non root mount canyon289 Linux - Hardware 1 02-21-2005 10:05 PM
mount permmissions and auto mount mokojin Slackware 3 02-28-2004 10:47 AM
help with mount points rmanocha Linux - Software 12 10-26-2003 01:32 PM
mount points... Jeffrey Linux - General 6 02-24-2001 12:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration