Ecreate script

Discussion in 'Server Operation' started by m u r, Jun 2, 2007.

  1. m u r

    m u r Member

    This script creates a new user account, but I want it to limit the amount of storage space that account is allowed. Can anyone help me do this? Thanks.

    Code:
    #!/bin/bash
    emailgroupfolder=/home/emailgroup	## the folder in which you want new emailaccount homes to be created
    emailgroupname=emailgroup		## the linux group to which your new email users will be assigned
    useraddpath=/usr/sbin/useradd		## the path to the command useradd on your system (it's probably the same)
    
    fname=$1
    lname=$2
    username=$3
    password=$4
    userlist=`cat /etc/passwd | cut -d: -f1 -s | grep $username`
    
    enc_password=`/usr/bin/htpasswd2 -nb $username $password | cut -f2 -d :`
    
    if [ $# -ne 4 ]; then
    	echo "error6" ## There are more than or fewer than 4 arguments (Somebody has put down their middle name, or left off their last name)
    	exit 1
    fi
    if [ "$username" = "$userlist" ] ; then 	## Username already exists on the system
    	echo "error7" 
    	exit 7;
    fi
    case "$fname" in
    	*[!a-zA-Z0-9]*) echo "error2"; exit 2;; ## First Name contains illegal characters
    	*);;
    	esac
    case "$lname" in
    	*[!a-zA-Z0-9]*) echo "error3"; exit 3;; ## Last Name contains illegal characters
    	*);;
    	esac
    case "$username" in
    	*[!a-zA-Z0-9]*) echo "error4"; exit 4;; ## Username contains illegal characters
    	*);;
    	esac
    case "$password" in
    	*[!a-zA-Z0-9]*) echo "error5"; exit 5;; ## Password contains illegal characters
    	*);;
    	esac
    /usr/sbin/useradd -m -c "$fname $lname" -d $emailgroupfolder/$username -p $enc_password -s '/bin/false' -g $emailgroupname -G 8 $username
    echo "success"
    exit 0
    fi
    
     
    Last edited: Jun 2, 2007
  2. falko

    falko Super Moderator Howtoforge Staff

    First, you must enable quotafor that system. Afterwards you can set quota with the setquota command:
    Code:
    man setquota
     

Share This Page