Subject: bin/20272: Daily quotas check
To: None <>
From: None <>
List: netbsd-bugs
Date: 02/10/2003 02:23:33
>Number:         20272
>Category:       bin
>Synopsis:       No daily checks for disk quotas
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Feb 09 16:24:00 PST 2003
>Originator:     Mishka
>Release:        NetBSD 1.6_STABLE
Terabyte ACS
NetBSD (stable and current branches)
Architecture: i386
Machine: i386


After some needs in disk quotas I have enabled its and found that
no any check of quota usage, and even quota has been exceeded there
is no way for non-shell users to know when their quota stats. Of
course, they will know about limits overrides when their files
can't be written to server and other services (mail, databases,
and so on) will fails, but it is invalid, IMHO.


Just enable disk quotas.


The script at the and of this PR used by me in every day checks
(called from daily.local) and works as follows (sample output):

Running /etc/daily.local:

Check user quotas:
                        Block limits               File limits
User            used    soft    hard  grace      used    soft    hard  grace
mishka    +-  246504  200000  400000 12days      2429       0       0       

Notify quota exceeders: mishka.

Check group quotas:
Group quotas disabled.
---- END OF QC OUTPUT ----

The script is controlled within two variables (customized in daily.conf):

    check_quotas		- do quota checks or not.
    notify_quota_exceeders	- notify quota exceeders if any or not.

Thus, it will check for quotas on all filesystems, and if quotas
disabled the appropriate message will be displayed (what's a sense
of check_quotas in YES, if all quotas disabled?). The quota exceeders
only are shown. If notify_quota_exceeders=YES, then all such users
will receive the message with quota(1) report. If user was deleted,
but him files are stored on disk and overlaps him quotas, the
notification must be made, but it is impossible (no such user); in
this case as well as in case of any other error, no notification
will be sent and asterisk will be shown near that user in "Notify
quota exceeders" report. I.e.:

    Notify quota exceeders: janedoe 1000* johndoe.

#!/bin/sh -
# $Id: daily.local,v 1.3 2003/02/09 23:23:44 mishka Exp $

if checkyesno check_quotas; then
	echo ""
	echo "Check user quotas:"
	U_QUOTA=$(repquota -u -a)
	U_XCDRS=$(echo "${U_QUOTA}" | grep "+")
	if [ -n "${U_XCDRS}" ] ; then
		echo "${U_QUOTA}" | head -2
		echo "${U_XCDRS}"
		if checkyesno notify_quota_exceeders; then
			echo ""
			echo -n "Notify quota exceeders:"
			EXCEEDERS=$(echo "${U_XCDRS}" \
				| awk '{print $1}' | sed 's:[-+][-+]$::')
			for VIOLATOR in ${EXCEEDERS}; do
				echo -n " ${VIOLATOR}"
				userinfo -e ${VIOLATOR} \
				&& quota -u ${VIOLATOR} \
					| mail -s \
					"WARNING: you quota has been exceeded" \
					${VIOLATOR} \
				|| echo -n "*"
			echo "."
	elif [ -z "${U_QUOTA}" ] ; then
		echo "User quotas disabled."

	echo ""
	echo "Check group quotas:"
	G_QUOTA=$(repquota -g -a)
	G_XCDRS=$(echo "${G_QUOTA}" | grep "+")
	if [ -n "${G_XCDRS}" ] ; then
		echo "${G_QUOTA}" | head -2
		echo "${G_XCDRS}"
	elif [ -z "${G_QUOTA}" ] ; then
		echo "Group quotas disabled."

Best regards,