Unix-Mgt

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    
     # display some info
     print 'uid: ', $user->uid, "\n";
     print join(', ', $user->groups()), "\n";
    
     # set some properties
     $user->gid('websters');
     $user->shell('/bin/bash');
     $user->add_to_group('postgres');
    
     # create user account
     $user = Unix::Mgt::User->create('vera');
    
     # get user account, creating it if necessary
     $user = Unix::Mgt::User->ensure('molly');
    
     # get group
     $group = Unix::Mgt::Group->get('www-data');
    
     # display some info
     print 'gid: ', $group->gid, "\n";
     print join(', ', $group->members()), "\n";
    
     # add a member
     $group->add_member('tucker');

DESCRIPTION

    Unix::Mgt provides simple object-oriented tools for managing your
    Unixish system. Currently this module provides tools for managing users
    and groups. Other tools may follow as they evolve.

    Unix::Mgt does not directly manipulate any of the system files such as
    /etc/passwd. This module uses Perl's built-in Unix functions such as
    getgrent to get information, and Unix's built-in programs such as
    adduser.

 Early release

    In the spirit of "release early, release often", I'm releasing this
    version of Unix::Mgt before it has all the features that might be
    expected. This version does not include methods for removing users from
    groups, renaming users or groups, or several other methods.

Unix::Mgt::User

    A Unix::Mgt::User object represents a user in the Unix system. The
    object allows you to get and set information about the user account. A
    user object is created in one of three ways: get, create, or ensure.
    The new method is an alias for get.

    Unix::Mgt::User objects stringify to the account's name. For example,
    the following code would output miko.

     $user = Unix::Mgt::User->get('miko');
     print $user, "\n";

 get

    Unix::Mgt::User->get() retrieves user account information using
    getpwnam or getpwuid. The single param for this method is either the
    name or the uid of the user.

     $user = Unix::Mgt::User->get('vera');
     $user = Unix::Mgt::User->get('1010');

    If the user is not found then the do-not-have-user error id is set in
    $Unix::Mgt::err_id and undef is returned.

 create

    Unix::Mgt::User->create() creates a user account. The required param
    for this method is the name for the new account.

     $user = Unix::Mgt::User->create('vera');

    If the system param is true, then the account is created as a system
    user, like this:

     $user = Unix::Mgt::User->create('lanny', system=>1);

    create() uses the Unix adduser program.

 ensure

    Unix::Mgt::User->ensure() gets a user account if it already exists, and
    creates the account if it does not. For example, the following lines
    ensures the molly account:

     $user = Unix::Mgt::User->ensure('molly');

 name

    Returns the name of the user account. Currently this method cannot be
    used to set the account name.

     print $user->name(), "\n";

 uid

    Returns the user's user id (uid).

     print $user->uid(), "\n";

 passwd

    Returns the password field from getpwname(). This method will not
    actually return a password, it will probably just return *.

     print $user->passwd(), "\n"; # probably outputs "*"

 gid

    Sets/gets the gid of the user's primary group. Called without params,
    it returns the user's gid:

     print $user->gid(), "\n";

    Called with a single param, gid() sets, then returns the user's primary
    group id:



( run in 0.933 second using v1.01-cache-2.11-cpan-39bf76dae61 )