WANTED: Script for add users

Richard John Botting rbottin at atl.calstate.edu
Sun Jun 3 15:56:23 AEST 1990


We have spent 3 or four years working on scripts to this.
They are adapted to creating a class of students at one go.
You may have to change the names and dirctories of the prototype
dot files - which are where SCO Xenix/386 (1989) puts'em.
You may also have to change the ..BE field to something else (RTFM).
Disclaimer....This has survived much but is still evolving...use with care...
and don't blame us if it goes wrong...
-------------------------cut here-------------------------------
: "Interactive script to add a user"
: usage: newuser
:    or: newuser userid
:    or: newuser userid groupid
:

# change by M. Brenner to enable locking on password file
# Thu Dec  7 12:09:28 PST 1989
if [ -f /etc/pw..LOCK ]
  then echo "Looks like someone else is already editting it"; exit 1
  else cat /dev/null >/etc/pw..LOCK
fi
trap "rm /etc/pw..LOCK && exit || exit" 1 2 3
# end of change

if [ ! -w /etc/passwd ]
then
     echo "** you must be super-user to add new users **"
     echo "** abort **"
# following line added by M. Brenner, 03 Jan 90
     rm /etc/pw..LOCK && exit 1 || exit 1
     exit 1
fi

     echo "**$userid already exists **"
     echo "** abort **"
# following line added by M. Brenner, 03 Jan 90
     rm /etc/pw..LOCK && exit 2 || exit 2
     exit 2
fi
echo looking for new user id number & uid=`/usr/bin/cut -f3 -d: /etc/passwd|sort
 -n|tail -1`
uid=`expr $uid + 1`
while true
do
        if [ $# = 0 ]
        then
                echo "Select group for $userid from student, faculty, intern, ..
."
                echo; echo -n 'Input a group name: '
      echo $gname is not in /etc/group
        fi
done

echo "enter user info (name,etc)"
echo "user info: "
read uinfo
if ls -d /usr/$gname
then echo exists
fi
echo "enter HOME directory (default /usr/$gname/$userid): "
read home
if [ -z "$home" ]
echo $userid will have $home as his/her home directory.
echo "enter login shell (default /bin/sh): "
read shell
if [ -z "$shell" ]
then
     shell=/bin/sh
fi
if file "$shell" | grep "executable" >/dev/null
then
     echo "Shell is ok."
else
     echo "shell doesn't exist or isn't executable **"
     echo "** using /bin/sh **"
     shell=/bin/sh
 ? (y/n): "
read yn
if [ "$yn" != "y" ]
then
     echo "$userid not created **"
     echo "** abort **"
# following line added by M. Brenner, 03 Jan 90
     rm /etc/pw..LOCK && exit 4 || exit 4
     exit 4
else
     echo entering user $userid in /etc/passwd
     chmod 700 /etc/passwd
     echo "$userid:,..BE:$uid:$gid:$uinfo:$home:$shell" >> /etc/passwd
     chmod 444 /etc/passwd
     echo "$userid is entered into /etc/passwd"
     mkdir $home;chown $userid $home;chgrp $gname $home
     ls -ld $home; echo "created"
     pwadmin -f $userid
     echo setting up dot files

# loops created and csh stuff added by dick/RJB Jan15th 1990
# mailrc and exrc added dick/RJB Feb 3rd 1990
     for dotfile in profile logoutsh mailrc exrc
     do

     for dotfile in login cshrc logout
     do
        cp /usr/lib/mkuser/csh/$dotfile $home/.$dotfile || {
                echo "$0: Cannot create $home/.$dotfile" >&2
# following line added by M. Brenner, 03 Jan 90
                rm /etc/pw..LOCK && exit 1 || exit 1
                exit 1
        }
     done

        chmod 755 $home/.[a-z]*
        chgrp $gname $home/.[a-z]*
        chown $userid $home/.[a-z]*
        echo Listing of $home;ls -al $home
        rm /etc/pw..LOCK && exit || exit 
fi
----------------------cut here---------------------

I hope it helps and saves some of the hastles we've had...
Richard J Botting
Rbottin at atl.calstate.edu
PS. I hope it makes it thru the mail ok...
dick



More information about the Comp.unix.questions mailing list