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