Setting a Users Quota when creating account.

Pete Nesbitt pete at linux1.ca
Fri Jun 4 02:00:35 UTC 2004


On June 2, 2004 10:03 am, Steve Buehler wrote:
> I have done some searching and haven't found what I am looking for
> yet.  Maybe I am just looking in the wrong place.  Does anybody know of a
> simple perl script that I could run like the following:
> scriptname username passwd softlimit hardlimit
> What I want it to do is to create a user on my RHEL 3.x system and set the
> user and group quotas for that person with their soft limit and hard
> limit.  The username would be the same as the group name.  Would be nice if
> the script would change the quotas for a user who is already on the system
> if an command line option is used to tell it to.  But the priority for me
> is just to get one to do it while adding the user.
>
> Thanks
> Steve


Hi Steve,
You should keep the list on the recipient list as there are many talented 
people here.
Anyway, here is a bash script that should do what your after. I have tested it 
as far as creating users and setting passwd's but I am not running quotas at 
home so, you should confirm that aspect before going live.(of course, test 
the whole thing yourself anyway!)

#!/bin/bash
#
#read a file with one new account entry per line
# format of source file is "users real name,userid,password"
# set quotas based on a template quota account.
#
# in the edquota line, 
# "templateID" is an existing users quota to use as a template


username_file=/tmp/users_names2add.txt
status_log=/tmp/new_user.log

while read newuser
 do
  username="`echo $newuser|cut -d, -f1`"
  userid="`echo $newuser|cut -d, -f2`"
  userpass="`echo $newuser|cut -d, -f3`"

  useradd -c "`echo $username`" $userid 2>> $status_log >&2
  edquota -p templateID $userid 2>> $status_log >&2
  echo $userpass | passwd --stdin $userid 2>> $status_log >&2
 done < $username_file

# end of script

Hope that works for you.
-- 
Pete Nesbitt, rhce





More information about the redhat-list mailing list