:
#!sh
#
# "@[$]rmuser	2.3  08/04/84 12:25:22
#
#
# /usr/bin/rmuser
#
# shell proc to remove a user from system
# First version 2/18/84  WILLIAM C. HAMMEL JULY, 1984
#

pwfile=/etc/passwd
spwfile=/usr/lxmx/Save/passwd

group=/etc/group
sgroup=/usr/lxmx/Save/group

tmp=/tmp/rmu$$
root=/
tmp2=/tmp/rmugrp$$

trap "rm -f $tmp $tmp2;exit" 0 1 2 13 15

/bin/echo
/bin/echo
/bin/echo 'PLEASE ENTER LOGIN FOR USER TO BE REMOVED'
/bin/echo 'ENTER> \c'

lognam=`gets`

# do we know about this user at all, if so do it, if not exit
if egrep "^$lognam:" $pwfile > /dev/null; then
	/bin/echo DELETING $lognam FROM GROUPS IN $group
	# make up a sed script to delete the user from /etc/group
		/bin/echo s/,$lognam// > $tmp
		/bin/echo s/:$lognam,/:/ >> $tmp
		/bin/echo s/:$lognam/:/ >> $tmp
		sed -f $tmp $group > $tmp2
		mv $tmp2 $group
		chmod 644 $group
		rm -f /usr/spool/mail/$lognam
	/bin/echo LISTING ALL FILES OWNED BY $lognam IN /tmp/files.$lognam \(THIS WILL TAKE A WHILE\)
	find / -user $lognam -type f -print > /tmp/files.$lognam
	more -d /tmp/files.$lognam
# Get the new owner or delete files

	/bin/echo "PLEASE ENTER THE NAME OF THE NEW OWNER OR d TO DELETE THESE FILES"
	/bin/echo 'ENTER> \c'
	nuname=`gets`
	case $nuname in
		 d)
			ed /tmp/files.$lognam <<- END > /dev/null
				1,\$s/^/rm -f /
				w
				q
			END
			chmod +x /tmp/files.$lognam
			/tmp/files.$lognam
			rm -f /tmp/files.$lognam
			/bin/echo FILES OF $lognam DELETED
			;;
		*)
			if egrep "^$lognam:" $pwfile > /dev/null; then
				ed /tmp/files.$lognam <<- END > /dev/null
					1,\$s/^/chown $nuname /
					w
					q
				END
				chmod +x /tmp/files.$lognam
				/tmp/files.$lognam
				/bin/echo OWNERSHIP CHANGED TO $nuname

			else
				/bin/echo $lognam is not in the passwd file
				rm -f /tmp/files.$lognam
				exit 1
			fi
	esac
	/bin/echo LISTING ALL DIRECTORIES OWNED BY $lognam IN /tmp/dirs.$lognam \(THIS WILL TAKE A WHILE\)
	if find / -user $lognam -type d -print > /tmp/dirs.$lognam; then
		/bin/echo THE DIRECTORIES OWNED BY $lognam ARE
		more -d /tmp/dirs.$lognam
		/bin/echo "PLEASE ENTER THE NAME OF THE NEW OWNER OR d TO DELETE THESE DIRECTORIES"
		/bin/echo 'ENTER> \c'
		nuname=`gets`
		case $nuname in
			d)
				ed /tmp/dirs.$lognam <<- END > /dev/null
					1,\$s/^/rm -fr /
					w
					q
				END
				chmod +x /tmp/dirs.$lognam
				/tmp/dirs.$lognam
				rm -f /tmp/dirs.$lognam
				/bin/echo DIRECTORIES OF $lognam DELETED
				;;
			*)
				if egrep "^$nuname:" $pwfile > /dev/null; then
					ed /tmp/dirs.$lognam <<- END > /dev/null
						1,\$s/^/chown $nuname /
						w
						q
					END
					chmod +x /tmp/dirs.$lognam
					/tmp/dirs.$lognam
					/bin/echo OWNERSHIP CHANGED TO $nuname

				else
					/bin/echo $nuname is not in the passwd file
					rm -f /tmp/dirs.$lognam
					exit 1
				fi
		esac
	fi

	/bin/echo REMOVING $lognam FROM THE PASSWORD FILE
		sed -e "/$lognam/d" < $pwfile > $tmp
	mv $tmp $pwfile
	chmod 0644 $pwfile

	/bin/echo
	/bin/echo
	/bin/echo REMOVING $lognam FROM BACKUP PASSWD, GROUP AND WHOIS FILES\.
	cp $pwfile $spwfile
	cp $group $sgroup

cat << EOMSG
	User's home directory has not been removed from the daily automatic
	backup sequence nor from the manual backup sequence.  If this is
	appropriate, the administrator should delete the apropriate lines
	in the files /etc/autotar and /etc/backup.  This requires superuser
	status.
EOMSG

	exit 0
else 
	/bin/echo
	/bin/echo
	/bin/echo $lognam IS NOT IN THE PASSWD FILE

	exit 1
fi


Return to Home Page
Return to Metayoga Page
Return to shell Page


The URL for this document is:
http://graham.main.nc.us/~bhammel/graham/SHELL/rmuser.html
Created: 1997
Last Updated: May 28, 2000 Email me, Bill Hammel at
bhammel@graham.main.nc.us
READ WARNING BEFORE SENDING E-MAIL