Operating System - HP-UX
1825889 Members
3317 Online
109689 Solutions
New Discussion

Re: Determining last user logon

 
SOLVED
Go to solution
Clifton Smith
Occasional Advisor

Determining last user logon

I administer a trusted system (all password entries in /tcb/files/auth/*), and need some way to determine the last logon of all users in /etc/passwd for a particular system.

Is there any way to use the u_suclog field in the tcb encrypted file or ANY other way to determine for each user in /etc/passwd when their last logon was? We are going to use this for clean up purposes on the system..... Any assistance is GREATLY appreciated..
10 REPLIES 10
Slawomir Gora
Honored Contributor

Re: Determining last user logon

Hi,

you can use command for each user:

last user_name | head -n1
Rodney Hills
Honored Contributor

Re: Determining last user logon

Would the "last" command work for you?

I've merged the output of "last" with "/etc/passwd" via a perl program and have generated such lists for myself.

-- Rod Hills
There be dragons...
Steven E. Protter
Exalted Contributor

Re: Determining last user logon

IF the user logged on since the last time the /var/adm/wtmp file was cleared.

last

will show it.

If not, passwd -sa might provide some useful data or some other variation, though this may only show the last time they changed their password. That isn't useless, may be helpful.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Geoff Wild
Honored Contributor

Re: Determining last user logon

last userid

last userid |head -1

Rgds...Geoff

Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Rodney Hills
Honored Contributor
Solution

Re: Determining last user logon

Here is the perl program I used-

#!/usr/local/bin/perl
# Show last logins for every user in /etc/passwd
#
open(LASTLOGIN,"last|") || die "Can not run 'last' command\n";
while () {
next if $_ eq "";
if (/^wtmp begin/) {$begin=$_ ; next};
($name,$tty,$date)=/(\S+)\s+(\S+)\s+(\S+\s+\S+\s+\S+)/;
$user{$name}=$date unless $user{$name};
}
print $begin;
close(LASTLOGIN);
open(PASSWD,"/etc/passwd") || die "Can not open '/etc/passwd'\n";
while () {
next if /^\+/;
($name,$rest)=split(":");
$user{$name}="**NOT USED**" unless $user{$name};
}
foreach $name (sort keys(%user)) {
printf "%-10s %s\n",$name,$user{$name};
}


HTH

-- Rod Hills
There be dragons...
Clifton Smith
Occasional Advisor

Re: Determining last user logon

Rod - Thanks !! This is just what I needed..... I would like to press my luck to ask one more thing, however. I am not very familiar with Perl, and I would like to know how to narrow down the search in /etc/passwd to users with a specific word in their logon path.. For instance, in the POSIX world, it would look something like "grep (string) /etc/passwd". I am unfamiliar with how to insert this into the Perl script that you have submitted. Are you, or anyone in this thread, familiar enough with Perl to add some insight?

Thanks
Rodney Hills
Honored Contributor

Re: Determining last user logon

If you look at the line

next if /^\+/;

This statement skips those lines that begin with "+". What ever regular expression can be used. Example-

To ignore users who are using ksh.
next if /bin\/ksh/;

You could also replace the follwing split statement with-
($user,$pswd,$uid,$gid,$comment,$path,$shell)=split(":",$_);

Then do comparisons on the a field-
next unless $comment=~/test/;

Would only keep entries with "test" in the comment field (note "unless" clause).

Perl is the swiss army knife for system admins.

HTH

-- Rod Hills
There be dragons...
Patrick Wallek
Honored Contributor

Re: Determining last user logon

An easier, and quicker way to get the last login is:

# /usr/lbin/getprpw -m ulogint user_id

Slawomir Gora
Honored Contributor

Re: Determining last user logon

Hi,

you can use shell script:


#!/bin/sh

for user in `cat /etc/passwd | awk -F':' '{print $1}'`
do
RES=`last $user | head -n1`
[ "$RES" = "" ] || echo $RES
done
doug hosking
Esteemed Contributor

Re: Determining last user logon

Patrick, did you mean slogint instead of ulogint? (successful vs. unsuccessful)