Directory tools for Edubuntu server

Gerald Drouillard gerrylist at drouillard.ca
Wed Jun 17 17:20:50 BST 2009


On 6/17/2009 12:01 PM, Andy Figueroa wrote:
> I love good gui tools for managing users, but they are tedious and time
> consuming for making many changes, additions, or deletions.
>
> Depending on what user and group items are being managed, the most powerful
> tool for changing group permissions for established users is directly
> editing the /etc/group file as root using a text editor.
>
> Likewise, adding and deleting users is most expediently done by the
> administrator as root from the command line.  For adding many users at a
> time, a little shell script like that below makes my day.  This is an actual
> except from the script that I use:
>
Here is the one I use that seems a little easier....IMO:

#!/bin/bash
#list all users...
#cut -d: -f1 /etc/passwd
#space delimited file of users separated by line returns
#groupadd student

toLower() {
     echo $1 | tr "[:upper:]" "[:lower:]"
}
toUpper() {
     echo $1 | tr "[:lower:]" "[:upper:]"
}
logIt() {
     echo $1
     echo $1 >>log.txt
}
rm log.txt
unixfile=unix_user_list.txt
#Remove any CRLF's
tr -d "\015" < students.txt > $unixfile
cat $unixfile | \
while read FIRSTNAME MIDDLE LASTNAME PASSWORD
do
     username=`toLower ${FIRSTNAME}.${LASTNAME}`
     egrep "^$username" /etc/passwd >/dev/null
     if [ $? -eq 0 ]; then
	logIt "Exists: $username"
     else
         homedir=/home/student/$username
	xpass=`mkpasswd $PASSWORD`
#	echo $username $PASSWORD $xpass
         useradd -f 360 -d $homedir -c "$FIRSTNAME $MIDDLE $LASTNAME" -m 
-s /bin/bash -g student -G 
dialout,cdrom,floppy,audio,dip,plugdev,scanner -p $xpass "$username"
	if [ $? -eq 0 ]; then
	    chmod 700 $homedir
	    logIt "Added: $username $PASSWORD"
	else
	    logIt "Error $?: ${username}"
	fi
     fi
done
rm $unixfile


-- 
Regards
--------------------------------------
Gerald Drouillard
Technology Architect
Drouillard & Associates, Inc.
http://www.Drouillard.biz



More information about the edubuntu-users mailing list