?
Solved

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

Posted on 2010-01-08
6
Medium Priority
?
1,991 Views
Last Modified: 2013-12-27
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
0
Comment
Question by:R4JK
6 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 26208885
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
 
LVL 85

Expert Comment

by:ozo
ID: 26208965
#!/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
 
LVL 7

Expert Comment

by:turnbulld
ID: 26212173
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 38

Accepted Solution

by:
yuzh earned 2000 total points
ID: 26280004
0
 

Expert Comment

by:NoBug
ID: 26280254
#!/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
 

Expert Comment

by:NoBug
ID: 34376631
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses
Course of the Month14 days, 2 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question