Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 May 2002 07:58:39 -0700 (PDT)
From:      David Xu <bsddiy@yahoo.com>
To:        current@freebsd.org, Mark Murray <mark@grondar.za>
Subject:   Re: Perl scripts that need rewiting - Any volunteers? (rmuser shell script ready)
Message-ID:  <20020509145839.71143.qmail@web20904.mail.yahoo.com>

next in thread | raw e-mail | index | archive | help
--0-2129547160-1020956319=:70351
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

here is the rmuser program written in SHELL script.
I have spent one hour on writting it down and tested. 
please see attached.

David


__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Mother's Day is May 12th!
http://shopping.yahoo.com
--0-2129547160-1020956319=:70351
Content-Type: text/plain; name=rmuser
Content-Description: rmuser
Content-Disposition: inline; filename=rmuser

#! /bin/sh

PW=/usr/sbin/pw

usage() {
	echo "$0 [-y] [username]"
	exit 1
}

if [ $# -gt 2 ]; then
	usage
	exit 1
fi

confirm=1
if [ $# -eq 2 ]; then
	case $1 in
	[-][y])
		confirm=0
		;;
	*)
		usage
	esac
	shift;
fi

if [ $# -eq 1 ]; then
	user=$1
else
	while true
	do
		echo -n 'Enter login name for user to remove: '
		read user
		case $user in
			"")
				;;
			*)
				$PW usershow $user > /dev/null 2>&1
				if [ $? -eq 0 ]; then
					break;
				else
					echo 'Sorry, login name not in password database.'
				fi
				;;
		esac
	done
fi

rmhome='-r'

if [ $confirm -eq 1 ]; then
	echo 'Matching password entry:'
	echo

	$PW usershow $user
	if [ $? -ne 0 ]; then
		exit 1
	fi
	echo
	echo -n 'Is this the entry you wish to remove? '
	read y
	case $y in
	[yY])
		;;
	*)
		echo "$0: Informational: User $user not removed."
		exit 0
		;;
	esac
	home=`$PW usershow $user | /usr/bin/cut -f 9 -d ':'` 
	echo -n "Remove user's home directory ($home)? "
	read y
	case $y in
	[Yy])
		;;
	*)
		rmhome=''
		;;
	esac
fi

echo /usr/bin/killall -KILL -u $user | su -m $user >/dev/null 2>&1
$PW userdel $user $rmhome
if [ $? -eq 0 ]; then
	echo "User account $user removed"
#else expect pw already reported error
fi


--0-2129547160-1020956319=:70351--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020509145839.71143.qmail>