I have a separate /home partition with ext4 filesystem. I have about 200 users whose usernames have a common prefix (e.g. 2010...). I have to allot 500 MB space limit (hard limit) for each users home directory. Instead of specifying space one by one I want to set the limit on one go by making use of the username prefix. How can it be done?
Asked
Active
Viewed 3,433 times
4
-
If you want the space limit to be based on the user's prefix, this can be done by using an handwritten script which parses the prefix and then sets the quota on the users home directories. – Jonathan Rioux Jan 26 '11 at 01:18
1 Answers
4
One way would be to create a template user, use edquota to set the quota for that template user. Then use setquota -p template_user -u real_user /filesystem
to assign the quota settings of template_user
to real_user
:
Something like this may work for you.
cat /etc/passwd | cut -d: -f 1 | grep ^prefix | \
xargs -I{} -n 1 setquota -p template_user -u {} /filesystem
You could build a file with the a list of the users and the settings so you can use the --batch option. Create a file that looks like
user1 block-softlimit block-hardlimit inode-softlimit inode-hardlimit
user2 block-softlimit block-hardlimit inode-softlimit inode-hardlimit
user4 block-softlimit block-hardlimit inode-softlimit inode-hardlimit
user5 block-softlimit block-hardlimit inode-softlimit inode-hardlimit
user5 block-softlimit block-hardlimit inode-softlimit inode-hardlimit
Then use a command like cat above_file | setquota--batch /filesystem
There are lots of different ways you can hack out a quick script, just check the setquota man page.