Lastlog
NAME
Sys::Lastlog - Provide a moderately Object Oriented Interface to lastlog files on some Unix-like systems.
SYNOPSIS
use Sys::Lastlog;
my $ll = Sys::Lastlog.new();
while (my $llent = $ll.getllent() )
{
say $llent;
}
See also the bin/rakulastlog
in the distributed files.
DESCRIPTION
The lastlog file provided on most Unix-like systems stores information about when each user on the system last logged in. The file is sequential and indexed on the UID (that is to say a user with UID 500 will have the 500th record in the file). Most systems do not provide a C API to access this file and programs such as 'lastlog' will provide their own methods of doing this.
This module provides an Object Oriented Perl API to access this file in order that programs like 'lastlog' can written in Perl (for example the 'plastlog' program in this distribution) or that programs can determine a users last login for their own purposes.
The module provides three methods for accessing lastlog sequentially, by UID or by login name. Each method returns an object of either type Sys::Lastlog::Entry or Sys::Lastlog::UserEntry.
that itself provides methods for accessing the information for each record.
METHODS
new
The constructor of the class. Returns a blessed object that the other methods can be called on.
getllent
This method will sequentially return each record in the lastlog each time it is called, returning an undefined value when there are no more records to return. Because the lastlog file is indexed on UID if there are gaps in the allocation of UIDs on a system will there will be as many empty records returned ( that is to say if for some reason there are no UIDs used between 200 and 500 this method will nonetheless return the 299 empty records .) This returns an object of type Sys::Lastlog::UserEntry
getlluid( Int $uid )
This method will return a record for the $uid specified or an undefined value if the UID is out of range, it does however perform no check that the UID has actually been assigned it must simply be less than or equal to the maximum UID currently assigned on the system. Returns a Sys::Lastlog::Entry
list
This will return a list of
Sys::Lastlog::UserEntry objects representing
every user defined in the system. They will be returned in order of
ascending uid
(which may differ from that output by the lastlog
command on your system which may have them in the order they were added.)
Currently this is fairly inefficient as it will read each record of the
lastlog
file even if there is no corresponding user.
getllnam( Str $logname)
This will return the record corresponding to the user name $logname
or an undefined value if it is not a valid user name. Returns a
Sys::Lastlog::Entry
setllent
Set the file pointer on the lastlog file back to the beginning of the file for repeated iteration over the file using getllent() .
Sys::Lastlog::Entry
These are the methods of the class Sys::Lastlog::Entry that give access to
the information for each record in the lastlog
file.
time
The time in epoch seconds of this users last login. Or 0 if the user has never logged in.
timestamp
The DateTime corresponding to time
has-logged-in
This returns a Bool to indicate whether the user has ever logged in.
line
The line (e.g. terminal ) that this user logged in via.
host
The host from which this user logged in from or the empty string if it was a local login.
Sys::Lastlog::UserEntry
Objects of this type are returned by the methods list and
getllent. They will stringify to a format similar to the
output of a line from the command lastlog
on my system.
It contains the user details so that the methods can be used in a self-contained manner without having to look up the user details.
entry
This is the Sys::Lastlog::Entry describing the record for the user.
user
This is the System::Passwd::User object that describes the user that the record is for.