| Summary: | Listing all users in the passwd file | ||
|---|---|---|---|
| Product: | Base System | Reporter: | jamie <jamie> |
| Component: | bin | Assignee: | freebsd-bugs (Nobody) <bugs> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | 4.2-STABLE | ||
| Hardware: | Any | ||
| OS: | Any | ||
You might want to make a port out of this.. G'luck, Peter -- This sentence would be seven words long if it were six words shorter. On Tue, May 08, 2001 at 04:32:02PM +0100, jamie@psi-domain.co.uk wrote: > > >Number: 27205 > >Category: bin > >Synopsis: Listing all users in the passwd file > >Originator: Jamie Heckford > >Release: FreeBSD 4.2-STABLE i386 > >Organization: > Psi-Domain Limited > >Environment: > > FreeBSD storm.psi-domain.co.uk 4.2-STABLE FreeBSD 4.2-STABLE #2: Fri Mar 2 10:32:25 GMT 2001 > > >Description: > > I was recently trying to discover a way of getting a list of all users on > one of my systems, and could not find an easy way to do it. > > I discovered the following awk script that prints out all users on the system > (from /etc/passwd). (Courtesy of sendmail.org) > > awk -F: '$3 > 100 { print $1 }' /etc/passwd > > Which will print out a list of all users in the passwd file wuth a UID greater > than 100. > > Could this be turned into a command such as "userlist", and/or would it be > deemed usefull? State Changed
From-To: open->closed
The system provides the getpwent(3) routine to iterate through
the passwd file and also takes care of other sources (like NIS).
In a script you'd say s.t. like
perl -e 'while(($name)=getpwent){print "$namen"}'
No, we're not making separate executables for such one-liners.
There would be just too many :-)
|
I was recently trying to discover a way of getting a list of all users on one of my systems, and could not find an easy way to do it. I discovered the following awk script that prints out all users on the system (from /etc/passwd). (Courtesy of sendmail.org) awk -F: '$3 > 100 { print $1 }' /etc/passwd Which will print out a list of all users in the passwd file wuth a UID greater than 100. Could this be turned into a command such as "userlist", and/or would it be deemed usefull? Another good feature that many people get stuck on is for sending email to all users on the system. Maybe it could be included as part of the sendmail distro, with something like: awk -F: '$3 > 100 { print $1 }' /etc/passwd > /etc/mail/allusers and put in cron.daily. This could then be a default in /etc/mail/aliases: allusers: :include:/etc/mail/allusers What do you think? :) Jamie Fix: Tested the above and worked fine, just need someone to tell me its great or completly useless! :) How-To-Repeat: userlist -------- awk -F: '$3 > 100 { print $1 }' /etc/passwd Sendmail ------- awk -F: '$3 > 100 { print $1 }' /etc/passwd > /etc/mail/allusers echo "allusers: :include:/etc/mail/allusers" >> /etc/aliases ; newaliases echo "#\!/bin/sh" > /etc/periodic/350.allusers echo "awk -F: '$3 > 100 { print $1 }' /etc/passwd > /etc/mail/allusers" >> /etc/periodic/350.allusers chmod 0755 /etc/periodic/350.allusers