* Re: add/remove users
@ 1996-05-13 4:00 Iwao Jack Makino
0 siblings, 0 replies; 4+ messages in thread
From: Iwao Jack Makino @ 1996-05-13 4:00 UTC (permalink / raw)
How about this one?
I don't know about deleting, but ...and this' for ultrix, that we
used to use, but should work on Alpha since we still do I think...
---
#
# @(#)adduser.sh 7.1 (ULTRIX) 9/1/92
#
# Copyright (c) 1984, 1989, 1990, 1992 by
# Digital Equipment Corporation, Maynard, MA
# All rights reserved.
#
# This software is furnished under a license and may be used and
# copied only in accordance with the terms of such license and
# with the inclusion of the above copyright notice. This
# software or any other copies thereof may not be provided or
# otherwise made available to any other person. No title to and
# ownership of the software is hereby transferred.
#
# The information in this software is subject to change without
# notice and should not be construed as a commitment by Digital
# Equipment Corporation.
#
# Digital assumes no responsibility for the use or reliability
# of its software on equipment which is not supplied by Digital.
#
# Purpose: To add new users to the group and passwd file
# Usage: adduser
#
# Remarks:
# Interactive adduser script to ease the process of adding accounts.
#
# Modification History:
# 29-Jul-92 MWZ Allow more than just single digit user
# ids
# 09-Jul-92 SEL003 Don't allow *any* non-numeric characters in
# user ids (QAR 11297).
# 08-May-92 SEL002 Add users to newly created groups in /etc/group.
# 08-May-92 SEL001 Allow a negative response at the prompt
# to create a home directory.
#
# The maximum uid should really be read from /usr/include/limits.h
PATH=/etc/sec:/usr/etc/sec:/bin:/usr/bin:/usr/ucb
export PATH
UID_MAX=32000
umask 077
HOMELESS=0
if test ! -w /etc/passwd
then
echo "\aPlease su to root first."
exit 1
fi
# Trap signals
trap '/etc/unlockpw ; exit 1' 1 2
# Lock the passwd and group files
/etc/lockpw
exstat="$?"
if test $exstat -ne 0
then
exit $exstat
else
trap '/etc/unlockpw ; exit 0' 0
fi
#
# See if this system is a Yellow Pages client.
#
tail -1 /etc/passwd | grep "^[+-]:" > /dev/null
yp_used="$?"
tail -1 /etc/group | grep "^[+-]:" > /dev/null
if [ $? -eq 0 ] || [ $yp_used -eq 0 ]
then
/etc/unlockpw
echo "
\aThis system makes use of the Yellow Pages service for
user account administration. Please add the new user
by following the steps given in the Overview of Yellow
Pages chapter of the Network Management Guide."
exit 5
fi
# Get the category that the user will belong to
echo " "
echo "Enter the letter of the category that the person is in "
class=student
category=s
echo " f (faculty)"
echo " g (graduate)"
echo " s (student) "
echo " o (other)"
echo " t (staff)"
echo " q (quit) [student] : " \\c
read category
case "${category}"
in
f) class=faculty;;
g) class=graduate;;
s) class=student;;
o) class=other;;
t) class=staff;;
" ") category=s;;
q) exit;;
*) break;;
esac
if [ -z "$category" ]
then
category=s
fi
# Get new user's login name
while true
do
echo ''
echo 'Enter login name for new user (last name): ' \\c
if read USER
then
case "${USER}"
in
*:*)
echo 'Error, login name cannot contain colons.'
;;
'')
;;
?????????*)
echo 'Error, login name cannot be longer than 8 characters.'
;;
*)
break
;;
esac
else
exit 0
fi
done
# See if user already exists in passwd file, if so exit.
while true
do
if grep -s "^${USER}:" /etc/passwd
then
/etc/unlockpw
grep "^${USER}:" /etc/passwd
echo "\aUser ${USER} already in /etc/passwd file."
echo 'Enter login name for new user (last name first initial): ' \\c
read USER
# exit 5
else
break
fi
done
# Get the user ID for the new user. Sort the passwd file on uid,
# get the largest uid, validity check it as a valid number,
# then add one to it to get the new uid.
UID=`sort -nt: +2 -3 /etc/passwd | tail -1 | cut -d: -f3 | sed -n '/[0-9][0-9]*/p'`
# Check for valid ${UID}
if test ! "${UID}"
then
echo '\a'
echo "The password file (/etc/passwd) may be corrupt!"
echo "Exiting ${0} script. New entry not created!"
/etc/unlockpw
exit 1
fi
if test "${UID}" -gt ${UID_MAX}
then
echo '\a'
echo "A uid greater that the maximum allowed," ${UID_MAX} "was found."
echo "Exiting ${0} script. New entry not created!"
/etc/unlockpw
exit 1
fi
UID=`expr "${UID}" + 1`
X=${UID}
# SEL003 - ensure ALL the characters in the uid are numeric
N=`expr "${X}" : '^[0-9][0-9]*$'`
if [ ${N} -eq 0 ]
then
echo "Bad value for UID, must be an integer"
else
if [ ${X} -gt ${UID_MAX} ]
then
echo "UID must be less than ${UID_MAX}"
else
if grep -s "^[^:]*:[^:]*:${X}:" /etc/passwd
then
echo "There is another account with uid ${X}, is this ok [yes]? " \\c
if read Y
then
case "${Y}"
in
[yY]*|'')
;;
*)
continue
;;
esac
else
exit 1
fi
fi
UID=${X}
break
fi
fi
# Get new user's real name
while true
do
echo 'Enter full name for new user (First Last): '\\c
if read NAME
then
fname=`echo $NAME |cut -d" " -f1`
lname=`echo $NAME |cut -d" " -f2 `
case "${NAME}"
in
*:*)
echo 'Error, name may not contain colons.'
;;
'')
;;
*)
break
;;
esac
else
exit 1
fi
done
# Get the users's Student Id or S.S. number
echo " "
echo " "
echo 'Student ID or S.S. number (no hyphens or slashes) : ' \\c
read ident
echo " "
# Get the login group for the new user.
LOGGROUP=${class}
# Get the group ID for the new user
GID=`grep "^${LOGGROUP}:" /etc/group | cut -d: -f3`
if test ! "${GID}"
then
echo
echo "\aUnknown group: ${LOGGROUP}. Known groups are:"
echo
cut -d: -f1 < /etc/group | pr -t -l1 -4
while true
do
echo
echo "Do you want to add group ${LOGGROUP} to the /etc/group file [yes]? " \\c
if read ADDGROUP
then
case "${ADDGROUP}"
in
[yY]*|'')
echo ''
echo 'Adding new group to /etc/group file...'
/usr/etc/addgroup "${LOGGROUP}"
# Addgroup script returns the gid number.
GID=${?}
break 2
;;
[nN]*)
break
;;
*)
echo 'Error, invalid response, you must answer yes or no.'
;;
esac
else
exit 1
fi
done
else
break
fi
LOGGID=${GID}
PARENT=/usr/${class}
# Get the users login shell.
LSHELL=/bin/csh
echo "
Adding new user ..."
# Make sure parent directories for everything exist.
if test \! -d /usr/spool
then
mkdir /usr/spool
fi
if test \! -d /usr/spool/mail
then
mkdir /usr/spool/mail
fi
# Add the user to the password file.
echo "${USER}:Nologin:${UID}:${LOGGID}:${NAME}:${PARENT}/${USER}:${LSHELL}" >> /etc/passwd
if [ -f /usr/etc/mkpasswd -a -f /etc/passwd.pag ]
then
echo 'Rebuilding the passwd data base...'
( cd /etc ; /usr/etc/mkpasswd -u passwd )
fi
# Add the user to the auth file
echo "Adding the user the the authorization database"
if test -f /etc/auth.pag -a -f /usr/etc/sec/setauth
then
if [ ${class} = "student" ]
then
DEFPASSMAXLIFE=120
DEFPASSMINLIFE=0
else
DEFPASSMAXLIFE=180
DEFPASSMINLIFE=0
fi
MAXPASSLIFE=${DEFPASSMAXLIFE}
MAXPASSLIFE=`expr "${MAXPASSLIFE}" \* 24 \* 60 \* 60`
#
MINPASSLIFE=${DEFPASSMINLIFE}
MINPASSLIFE=`expr "${MINPASSLIFE}" \* 24 \* 60 \* 60`
#
AUTHMASK=07
echo "${UID}:Nologin:1:${MINPASSLIFE}:${MAXPASSLIFE}:${AUTHMASK}:0:${UID}:00:00:00" \
| /usr/etc/sec/setauth
fi
# Create home and bin directories, and set-up files
echo "Set up the home directory"
# SEL001 - Skip this if no home directory requested
if [ $HOMELESS -eq 0 ]
then
echo 'Creating home directory...'
cd "${PARENT}"
if [ "${?}" -ne 0 ]
then
echo "Unable to cd to parent directory ${PARENT}"
exit 1
fi
for I in "${USER}" "${USER}/bin"
do
if [ -d "${I}" ]
then
echo "${PARENT}/${I} already exists."
else
mkdir "${I}"
chmod 0751 "${I}"
/etc/chown "${USER}" "${I}"
chgrp "${LOGGROUP}" "${I}"
fi
done
for I in .profile .login .cshrc
do
if [ -s "${USER}/${I}" ]
then
echo "${PARENT}/${USER}/${I} already exists."
else
cp /usr/skel/${I} "${USER}/${I}"
chmod 0751 "${USER}/${I}"
/etc/chown "${USER}" "${USER}/${I}"
chgrp "${LOGGROUP}" "${USER}/${I}"
fi
done
else
echo "Warning: ${PARENT}/${USER} not created."
fi
# Unlock the password and group files
/etc/unlockpw
# Write out the information to the initpasswds file for accounting
# purposes.
echo "${category}":"${USER}":"${lname}" "${fname}":"${ident}":`date` >> /manage/users/initpasswds
# Set a password
echo "Until the password is set for ${USER} they will not be able to login."
while true
do
if passwd "${USER}"
then
break
fi
done
/etc/edquota -p student ${USER}
exit 0
--
=\\ll//====\\ll//====\\ll//====\\ll//====\\ll//====\\ll//====\\ll//====\\ll//=
You know we're gonna have a PARTY, PARTY!
http://cobweb.cord.edu/imakino/
Jeg heter Jack, Hvem er De?
Jag ar fron Japan
This is Jack' tmp account at MSU
^ permalink raw reply [flat|nested] 4+ messages in thread* add/remove users
@ 1996-05-10 4:00 adp
1996-05-13 4:00 ` Peter Mayne
1996-05-13 4:00 ` Kurt Pintoffl
0 siblings, 2 replies; 4+ messages in thread
From: adp @ 1996-05-10 4:00 UTC (permalink / raw)
Is there a program out there to add/remove users using a batch job (maybe
getting the input from a file).
We are in a university environment and usually need to add or remove various
group of students each semester.
Any idea will be appreciated.
adp@ark.ship.edu
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1996-05-13 4:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-05-13 4:00 add/remove users Iwao Jack Makino
-- strict thread matches above, loose matches on Subject: below --
1996-05-10 4:00 adp
1996-05-13 4:00 ` Peter Mayne
1996-05-13 4:00 ` Kurt Pintoffl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox