Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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 1:18

1 Answer 1

up vote 2 down vote accepted

One way would be to create a template user, use edquota to set the quota for that template user. Then use repquota -p template_user -u real_user /filesystem.

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.