LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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, 06:52 AM   #1
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
SCRIPT: check free space on partition base


As a side note: this is just a thread part of my main thread which is destinated at securing debian!

You should always keep an eye on available disk space ...
Code:
----------------------------------------------------------------------
created script to check free space
				[ /usr/local/sbin/check_free_space.sh ]
----------------------------------------------------------------------

#!/bin/sh

# --------------------------------------------------------------------
# purpose:	check free space per partition
#		notify admin if free space is critical
# args:		none
# deps:		bash, GNU utils, logger
# --------------------------------------------------------------------



# --------------------------------------------------------------------
# configuration
# --------------------------------------------------------------------
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 log() {
	/usr/bin/logger \
		-i -p kern.crit -t ${PROGNAME} \
		"CRITICAL: $1 has less than $2 KB space left"
}

function log_mail() {
	df --k -P --sync | mail \
		-s "$1 has less than $2 KB space left" ${ROOTMAIL}
	log $1 $2
}
# --------------------------------------------------------------------



# --------------------------------------------------------------------
# check free space per partition
# --------------------------------------------------------------------
df --k -P --sync | grep -v "Used" | while read i; do i=( ${i} )
	case ${i[5]} in
		/boot | /home )
			if [ ${i[3]} -lt 4096 ]; then
				log_mail ${i[5]} 4096
			fi
			;;

		/tmp | /usr )
			if [ ${i[3]} -lt 98304 ]; then
				log_mail ${i[5]} 98304
			fi
			;;

		/usr/local | /var/log | /var/spool/postfix )
			if [ ${i[3]} -lt 196608 ]; then
				log_mail ${i[5]} 196608
			fi
			;;

		/var/tmp )
			if [ ${i[3]} -lt 24576 ]; then
				log_mail ${i[5]} 24576
			fi
			;;

		*)
			if [ ${i[3]} -lt 262144 ]; then
				log_mail ${i[5]} 262144
			fi
			;;
	esac
done
# --------------------------------------------------------------------


exit $?

----------------------------------------------------------------------




----------------------------------------------------------------------
added check_free_space as cronjob     [ /etc/cron.d/check_free_space ]
----------------------------------------------------------------------
	0 */1 * * * root /usr/local/sbin/check_free_space.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
how to do a free space regular check baronlynx Linux - General 1 10-04-2005 08:01 PM
How to check free disk space TigerLinux Linux - Newbie 9 10-04-2005 06:04 PM
How do I check free partition space explorer Linux - General 5 04-14-2004 01:35 PM
Partition Free Space - Move /home to the new partition gregkise Linux - General 5 12-16-2003 11:19 PM
Partition Free Space? Gerardoj Linux - General 16 06-02-2003 02:16 AM


All times are GMT -5. The time now is 05:51 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration