This assumes you have installed quota using apt-get or yum.
yum install quota
Math
Before we set a quota that limits how much data can be stored in the /var directory, we need to determine the total block size of /var. Use the df command to view the total block size of /var. Let's say the the total block size of /var is 300000000. 300000000 bytes is 300 GB. This means that the /var directory can contain a total of 300 GB of data.
df
If repquota -a lists 4 users, to be very safe, we can divide 300,000,000 by 4, which makes 75,000,000. We should set a hard limit of 75,000,000 for each user, and a soft limit of 70,000,000. This will ensure the /var directory is never completely used.
Use the edquota command to edit the quota limit for the WebAdmins group.
edquota -u user1
The default limits will be 0. A hard limit of 250000000 is reasonable. We could also set the soft limit at 2000000000 so that an alert appears before reaching 250000000. Use the repquota command to verify that the quota has taken effect.
repquota -a
To test quota to ensure it is working, we can set a hard limit that is 1 block. For example, lets say the used block size is currently 123,456. We can set both the hard limit and soft limit to be 123,457. This should prevent us from being able to add aditional files to /var. Use the touch command to create a new file in /var, and then add junk data to the new file.
Use the df command to ensure the block size has not exceeded 123,456.
df
Use the repquota command again. If - - or - + or + - is displayed, the quota has been exceeded.
repquota -a
Soft limit can also be set for a user using the -T (time) option.
edquota -u username -T
Use the quotacheck command with the -mavug option to update the quota database.
quotacheck -mavug
A CRON job should be create to run quotacheck -mavug on an hourly basis, to resolve issues with mounting errors or filesystem errors.
An email can be sent to the WebAdmins once a day with a summary of the total size, used and available space on the /var directory.
#!/bin/bash
sender="From: John Doe"
recipient="webadmins@example.com"
subject="Disk Usage Report"
(printf "$(df -h)") | mailx -a "$sender" -s "$subject" $recipient