Return to BSD News archive
Newsgroups: comp.os.386bsd.questions Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!agate!howland.reston.ans.net!EU.net!Germany.EU.net!news.dfn.de!news.belwue.de!delos.stgt.sub.org!nadia.s.bawue.de!luva!migieger From: migieger@luva.lb.bawue.de (Michael Giegerich) Subject: Re: Adduser script References: <38uidr$fuv@newsflash.concordia.ca> Organization: private FreeBSD site Date: Sun, 30 Oct 1994 12:51:36 GMT Message-ID: <CyHL2F.DM3@luva.lb.bawue.de> Lines: 169 In article <38uidr$fuv@newsflash.concordia.ca>, Paul Quinn <p_quinn@ECE.Concordia.CA> wrote: > >I am looking for the adduser script. I have FreeBSD on the Walnut Creek CD >and I can't find the script. If someone can either point me to it or mail >me a copy, I'd appreciate it. Here's the script the sysadm bible (Unix System Administration Handbook by Nemeth e.a. *very* recommended) proposes. I'm sure you have to adapt it, but it gives the idea (I hope I'm not breaking any copyright by posting it, but the script is publically available via ftp)... ---------- snip ---------- snip ---------- snip ---------- snip ---------- #!/bin/csh # # adduser - simple script to add a new user. To execute # simply type adduser. Only root can run this script # successfully. # # onintr quit: # set freedisk=100 # directory containing sample . files set skeldir=/usr/local/adm/skel # set passwdfile=/etc/passwd set groupfile=/etc/group set phonelist=/usr/local/pub/phonelist # # set local_host=`hostname` # # get login, look for conflicts in /etc/passwd # and /usr/lib/aliases # set msg="enter login name, must be <= 8 characters" echo "junk" > /tmp/AD1$$ echo "junk" > /tmp/AD2$$ set aliasdone = no set good = no while ( ${good} == no ) echo ${msg} set dollar=$ set login=$< # look for it in the passwd file awk -F: '{print $1}' /etc/passwd | grep "^${login}${dollar}" \ > /tmp/AD1$$ if (! (-z /tmp/AD1$$)) then set msg="already used in passwd file, try again" else # look for it in the /usr/lib/aliases file fgrep ':' /usr/lib/aliases | awk -F: '{print $1}' | \ grep "^${login}${dollar}" > /tmp/AD2$$ if (! (-z /tmp/AD2$$)) then echo -n "already used in aliases file, entry is: " grep "^${login}:" /usr/lib/aliases echo -n "is that ok ??? " set answer = $< if (${answer} == n) then set msg="then try again, enter login id" else set good = yes set aliasdone = yes endif else set good = yes endif endif end rm /tmp/AD1* rm /tmp/AD2* # # get uid (biggest uid+1) # set uid=`sort -t: -nr +2 /etc/passwd | sed '1q' | awk -F: '{print $3}'` @ uid++ # # get gid (group) # set gid set null set msg="enter unix group" while ( ${gid} == ${null}) echo ${msg} set group=$< set gid=`grep "^${group}:" /etc/group | awk -F: '{print $3}'` set msg="group not in group file, try again" end # # get parent directory # set up home # set good=no set msg="enter location of home dir " echo ${msg} set top=$< set home = /${top}/${login} # # get finger info # echo "enter users full name, campus address, campus phone, home phone" set finger = $< # set entry="${login}::${uid}:${gid}:${finger}:${home}:/bin/csh" # echo " " echo login" "${login} echo group" "${group} echo uid" "${uid} echo gid" "${gid} # echo home" "${home} echo " " # # echo passwd entry is: echo ${entry} echo " " # set a=n echo "continue?(y/n) (last chance before scribbling on files)" set a=$< if ( $a == n ) exit # # add entry to passwd file # echo making passwd entry echo ${entry} >> $passwdfile # # add name to group file # echo making group entry set scpt=/^${group}/s/\$/,${login}/ echo ${scpt} > /tmp/ADD$$ sed -f /tmp/ADD$$ /etc/group > /tmp/newgroup$$ rm /tmp/ADD$$ mv /tmp/newgroup$$ $groupfile # # # add to the phonelist # echo making phonelist entry echo ${login}" "${finger} >> ${phonelist} # # make users home, copy in skeleton files # echo making home directory mkdir ${home} cp ${skeldir}/.login ${skeldir}/.logout ${skeldir}/.cshrc \ ${skeldir}/.exrc ${skeldir}/.mailrc ${home} find ${home} -exec chown ${login} {} \; -exec chgrp ${group} \; # # # set passwd # passwd ${login} quit: rm -f /tmp/*$$ ---------- snip ---------- snip ---------- snip ---------- snip ---------- -Michael -- ------------------------------+------------------------------ Michael Giegerich | migieger@luva.lb.bawue.de ------------------------------+------------------------------