Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: List all Users Directory

by eyepopslikeamosquito (Archbishop)
on Dec 14, 2016 at 07:46 UTC ( [id://1177768]=note: print w/replies, xml ) Need Help??


in reply to List all Users Directory

Be aware that Perl has a number of built-in functions relating to users and groups, for example: getlogin, getpwnam, getgrent. See Perl functions for fetching user and group info.

The simple code below, while perhaps not meeting your specific requirements, lists all users on a Linux box (including their home directories and other properties) by using the Perl builtin getpwent function:

use strict; use warnings; while ( my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $home, $shell) = getpwent ) { print <<"ALL_USER_ATTRS"; name = $name passwd = $passwd uid = $uid gid = $gid quota = $quota comment = $comment gcos = $gcos home = $home shell = $shell ALL_USER_ATTRS }

See also Re: adding a group to the Unix System for example code that calls getpwnam.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1177768]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-25 11:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found