Friday, September 07, 2012

POB script to assert if user quota is exceeded

Here is a Plain Old Bash (POB) script to assert the user quotas are OK. Should quotas exceed certain threshold provided as a parameter the script will return an exit code 1 with the description in stderr. Here is how to call it to find out who is using more than 85% space:
/usr/sbin/find-exceeded-quota.sh 85

Motivation

When trying to put a file via SFTP or creating a remote directory via SFTP we were getting:
Couldn't write to remote file "filename": Failure Couldn't create directory: Failure
Increasing log level for SSH did not help to clarify the issue:
$sudo vi /etc/ssh/sshd_config
...
# Logging
SyslogFacility AUTH
#LogLevel INFO
LogLevel VERBOSE
...
$ sudo service ssh restart
However other user accounts did not show the issue. It ended up being related to the user quota in use where "used" was nearly the same as the "hard" setting:
sudo repquota -a 
This simple POB script then can be used to check for certain percentage as explained. After getting the alert all the sysadmin will do is either delete files or increase quota:
sudo setquota -u user2 200000 200000 1500 1500 -a /
It is a good idea to automatically delete of course old files if that is possible.

No comments:

Followers