solaris "last" command does not give year information in output

Hi EE,

I need to get last login dates of each user on a system in the format dd/mm/yy

however when I run "last" to extract this data I get  for eg...

[server:root]#last USERA | head -1
USERA    pts/6        server_name Wed Oct 28 11:24 - 12:06  (00:42)

have two problems to consider here..
1. the format is not what I want here (dd/mm/yy)
2. the year informatino seems to be missing from the output

could anyone advise.

thanks
R4JK
R4JKAsked:
Who is Participating?
 
yuzhConnect With a Mentor Commented:
0
 
woolmilkporcCommented:
Hi,
there is a perl script (a one-liner) which could help you formatting the lastlog file closer to your needs.
http://www.hcidata.info/lastlog.htm
Some modifications may be necessary, but it's rather clearly explained on the page I pointed you to.
Good luck!
wmp
0
 
ozoCommented:
#!/usr/bin/perl
#this finds the most recent year for which the day matches the date
use POSIX;
@d{qw(Sun Mon Tue Wed Thu Fri Sat)}=(0..6);
@m{qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)}=(0..11);
$r=qr/\b(@{[join'|',keys %d]})\s+(@{[join'|',keys %m]})\s+(\d+)/;
while( <> ){
    s#$r#
      my $w=$d{$1};
      my $m=$m{$2};
      my $d=$3;
      $y=(localtime)[5];
      --$y while (localtime mktime(0,0,12,$d,$m,$y))[6] != $w;
      strftime("%d/%m/%y",0,0,12,$d,$m,$y)
    #e;
    print;
}
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
turnbulldCommented:
If it is the current year, Solaris doesn't show it in dates by default.  Same is true for day typically.  If the date it is displaying is the same as the current date, typically only the time is shown.
0
 
NoBugCommented:
#!/usr/bin/perl
#this finds the most recent year for which the day matches the date
use POSIX;
@d{qw(Sun Mon Tue Wed Thu Fri Sat)}=(0..6);
@m{qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)}=(0..11);
$r=qr/\b(@{[join'|',keys %d]})\s+(@{[join'|',keys %m]})\s+(\d+)/;
while( <> ){
    s#$r#
      my $w=$d{$1};
      my $m=$m{$2};
      my $d=$3;
      $y=(localtime)[5];
      --$y while (localtime mktime(0,0,12,$d,$m,$y))[6] != $w;
      strftime("%d/%m/%y",0,0,12,$d,$m,$y)
    #e;
    print;
}
0
 
NoBugCommented:
first perform the #uptime if ur server started above 1yr you will get the year info otherwise it will give you the month and date information only.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.