Sys::Utmp - Object(ish) Interface to UTMP files.
use Sys::Utmp;
my $utmp = Sys::Utmp->new();
while ( my $utent = $utmp->getutent() )
{
if ( $utent->user_process )
{
print $utent->ut_user,"\n";
}
}
$utmp->endutent;
Sys::Utmp provides a vaguely object oriented interface to the Unix user accounting file ( usually /etc/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.
As mentioned above the getutent method returns an object of the type Sys::Utmp::Utent which provides methods for accessing the fields in the utmp record. There are also methods for determining the type of the record.
The access methods relate to the common names for the members of the C struct utent - those provided are the superset from the Gnu implementation and may not be available on all systems: where they are not they will return the empty string.
The type of the record this will have a value corresponding to one of the constants (not all of these may be available on all systems and there may well be others which should be described in the getutent manpage or in /usr/include/utmp.h ) :
for convenience Sys::Utmp::Utent provides methods which are lower case versions of the constant names which return true if the record is of that type.
No methods or constants are exported by default.
These constants are exportable under the tag ':constants':
ACCOUNTING
BOOT_TIME
DEAD_PROCESS
EMPTY
INIT_PROCESS
LOGIN_PROCESS
NEW_TIME
OLD_TIME
RUN_LVL
USER_PROCESS
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 /usr/include/utmp.h
Jonathan Stowe, <Jonathan.Stowe@netscalibur.co.uk>
This Software is Copyright Netscalibur UK 2001.
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.