Name

Etc — Module for /etc directory data retrieval

Synopsis

The Etc module provides functions to retrieve user account-related data from files under /etc directory. This module is Unix-dependent.

Required Library

require ‘etc’

Example

require 'etc'

print "you must be ", Etc.getlogin, ".\n"

Module Functions

getlogin

Returns login name of the user. If this fails, try getpwuid.

getpwnam(name)

Searches in /etc/passwd file (or equivalent database), and returns password entry for the user name. See getpwnam(3) for details. The return value is a passwd structure, which includes the following members:

name

Username(string)

passwd

Encrypted password(string)

uid

User ID(integer)

gid

Group ID(integer)

gecos

Gecos field(string)

dir

Home directory(string)

shell

Login shell(string)

change

Password change time(integer)

quota

Quota value(integer)

age

Password age(integer)

class

User access class(string)

comment

Comment(string)

expire

Account expiration time(integer)

getpwuid([uid])

Returns passwd entry for the specified uid. If uid is omitted, uses the value from getuid. See getpwuid(3) for details.

getgrgid(gid)

Searches in /etc/group file (or equivalent database), and returns group entry for the gid. See getgrgid(3) for detail. The return value is a group structure, which includes the following members:

name

Group name(string)

passwd

Group password(string)

gid

Group ID(integer)

mem

Array of the group member names

getgrnam(name)

Returns the group entry for the specified ...

Get Ruby in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.