R4JK
asked on
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
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
#!/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;
}
#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
strftime("%d/%m/%y",0,0,12
#e;
print;
}
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
#!/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;
}
#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
strftime("%d/%m/%y",0,0,12
#e;
print;
}
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.
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