Sys::Utmp(3pm) User Contributed Perl Documentation Sys::Utmp(3pm)NAME
Sys::Utmp - Object(ish) Interface to UTMP files.
my $utmp = Sys::Utmp->new();
while ( my $utent = $utmp->getutent() )
if ( $utent->user_process )
See also examples/pwho in the distribution directory.
Sys::Utmp provides a vaguely object oriented interface to the Unix user accounting file ( sometimes /etc/utmp or /var/run/utmp). Whilst it
would prefer to use the getutent() function from the systems C libraries it will attempt to provide its own if they are missing.
This may not be the module that you are looking for - there is a User::Utmp which provides a different procedural interface and may well be
more complete for your purposes.
new The constructor of the class. Arguments may be provided in Key => Value pairs : it currently takes one argument 'Filename' which will
set the file which is to be used in place of that defined in _PATH_UTMP.
Iterates of the records in the utmp file returning a Sys::Utmp::Utent object for each record in turn - the methods that are available
on these objects are descrived in the Sys::Utmp::Utent documentation. If called in a list context it will return a list containing the
elements of th Utent entry rather than an object. If the import flag ':fields' is used then constants defining the indexes into this
list will be defined, these are uppercase versions of the methods described in Sys::Utmp::Utent.
Rewinds the file pointer on the utmp filehandle so repeated searches can be done.
Closes the file handle on the utmp file.
utmpname SCALAR filename
Sets the file that will be used in place of that defined in _PATH_UTMP. It is not defined what will happen if this is done between two
calls to getutent() - it is recommended that endutent() is called first.
No methods or constants are exported by default.
These constants are exportable under the tag ':constants':
These are the values that will be found in the ut_type field of the Sys::Utmp::Utent object.
These constants are exported under the tag ':fields' :
These provide the indexes into the list returned when "getutent" is called in list context.
Probably. This module has been tested on Linux, Solaris, FreeBSD ,SCO Openserver and SCO UnixWare and found to work on those platforms.
If you have difficulty building the module or it doesnt behave as expected then please contact the author including if appropriate your
Jonathan Stowe, <firstname.lastname@example.org>
This Software is Copyright Netscalibur UK 2001,
Jonathan Stowe 2001-2006
This Software is published as-is with no warranty express or implied.
This is free software and can be distributed under the same terms as Perl itself.
perl v5.14.2 2006-10-13 Sys::Utmp(3pm)
Check Out this Related Man Page
GETUTENT(3) Library functions GETUTENT(3)NAME
getutent, getutid, getutline, pututline, setutent, endutent, utmpname - access utmp file entries
struct utmp *getutent(void);
struct utmp *getutid(struct utmp *ut);
struct utmp *getutline(struct utmp *ut);
struct utmp *pututline(struct utmp *ut);
void utmpname(const char *file);
utmpname() sets the name of the utmp-format file for the other utmp functions to access. If utmpname() is not used to set the filename
before the other functions are used, they assume _PATH_UTMP, as defined in <paths.h>.
setutent() rewinds the file pointer to the beginning of the utmp file. It is generally a Good Idea to call it before any of the other
endutent() closes the utmp file. It should be called when the user code is done accessing the file with the other functions.
getutent() reads a line from the current file position in the utmp file. It returns a pointer to a structure containing the fields of the
getutid() searches forward from the current file position in the utmp file based upon ut. If ut->ut_type is RUN_LVL, BOOT_TIME, NEW_TIME,
or OLD_TIME, getutid() will find the first entry whose ut_type field matches ut->ut_type. If ut->ut_type is one of INIT_PROCESS,
LOGIN_PROCESS, USER_PROCESS, or DEAD_PROCESS, getutid() will find the first entry whose ut_id field matches ut->ut_id.
getutline() searches forward from the current file position in the utmp file. It scans entries whose ut_type is USER_PROCESS or
LOGIN_PROCESS and returns the first one whose ut_line field matches ut->ut_line.
pututline() writes the utmp structure ut into the utmp file. It uses getutid() to search for the proper place in the file to insert the
new entry. If it cannot find an appropriate slot for ut, pututline() will append the new entry to the end of the file.
getutent(), getutid(), getutline() and pututline() return a pointer to a static struct utmp on success, and NULL on failure.
The following example adds and removes a utmp record, assuming it is run from within a pseudo terminal. For usage in a real application,
you should check the return values of getpwuid() and ttyname().
int main(int argc, char *argv)
struct utmp entry;
system("echo before adding entry:;who");
/* only correct for ptys named /dev/tty[pqr][0-9a-z] */
system("echo after adding entry:;who");
system("echo after removing entry:;who");
/var/run/utmp database of currently logged-in users
/var/log/wtmp database of past user logins
XPG 2, SVID 2, Linux FSSTND 1.2
In XPG2 and SVID2 the function pututline() is documented to return void, and that is what it does on many systems (AIX, HPUX, Linux
libc5). HPUX introduces a new function _pututline() with the prototype given above for pututline() (also found in Linux libc5).
All these functions are obsolete now on non-Linux systems. POSIX 1003.1-2001, following XPG4.2, does not have any of these functions, but
struct utmpx *getutxent(void);
struct utmpx *getutxid(const struct utmpx *);
struct utmpx *getutxline(const struct utmpx *);
struct utmpx *pututxline(const struct utmpx *);
The utmpx structure is a superset of the utmp structure, with additional fields, and larger versions of the existing fields. The corre-
sponding files are often /var/*/utmpx and /var/*/wtmpx.
Linux glibc on the other hand does not use utmpx since its utmp structure is already large enough. The functions getutxent etc. are aliases
for getutent etc.
SEE ALSO utmp(5)