Re: adding all users to group
On Mon, 21 Jan 2002, dman wrote:
>On Mon, Jan 21, 2002 at 06:59:21PM -0800, mike@stonelx.ath.cx wrote:
>| Hi,
>| I'm trying to find a way to
>| add all my users to a group.
>| Is there a simple command to do this?
Simple if you can copy and paste into a file.
>Unfortunately this method will catch all system users too. An
You can easily do this with awk, instead of sed
/bin/cat /etc/passwd | awk -F':' '
( $3 >= 1000 ) && ( $3 < 65534 ) {
print $1
}'
All of the users on a Debian system have UID >= 1000. For some unknown (to
me) reason, the user `nobody' has a UID of 65534 (or -1)
That will list the local users, no biggie. Lets complete the program then,
shall we.
-------------------------- ~/bin/lsusers -----------------------
#!/bin/sh
# List all the users (non system) registered on a local system and network
# Cameron Kerr
# Born: 22 January 2002
#
# $Id: lsusers,v 0.2 2002/01/22 07:41:47 cameron Exp cameron $
# $Log: lsusers,v $
# Revision 0.2 2002/01/22 07:41:47 cameron
# Collate the output, sorting, and uniqing it.
#
# Revision 0.1 2002/01/22 07:37:22 cameron
# Initial revision
#
PATH=/bin:/usr/bin:/sbin:/usr/sbin
#Not all distributions have the same range of UIDs
system=
if [ -f /etc/slackware-version ]; then
system=slackware
minuid=500
maxuid=65534 # Dummy value, really
elif [ -f /etc/debian_version ]; then
system=debian
minuid=1000
maxuid=65533 # Debian `nobody' has UID of 65534
elif [ -f /etc/redhat-release ]; then
system=redhat
minuid=1000 # Guessing
maxuid=65533
else
echo "Unknown distribution. I do not know the minimum/maximim UID"
>&2
echo "Please update this script, and send update to" >&2
echo "cameron.kerr@paradise.net.nz" >&2
exit 1
fi
# This should take care of any local users.
{
cat /etc/passwd | awk -F':' '
( $3 >= '"$minuid"' ) && ( $3 < '"$maxuid"' ) {
print $1
}'
# We should probably take into account any NIS users.
if [ -n "`which ypcat`" ]; then
ypcat passwd | awk -F':' '{print $1}' 2> /dev/null
fi
# I don't know about LDAP...yet.
} | sort | uniq
------------------------------------------------------------
This will work (so far, on Slackware, Debian, and Redhat), with Local
accounts, and NIS accounts. More will eventually come...
Feel free to send me any updates.
Cameron Kerr
--
cameron.kerr@paradise.net.nz
http://homepages.paradise.net.nz/~cameronk/
Reply to: