?
Solved

How do I get the year to display using the lat command?

Posted on 2006-06-18
9
Medium Priority
?
562 Views
Last Modified: 2013-12-27
Using the followng command I can see when all the system reboots occurred but the date field does not include the year.

last | grep reboot

reboot    system boot                   Sun Jun 18 08:23
reboot    system boot                   Tue May 23 19:55
reboot    system boot                   Tue Apr 18 11:15
reboot    system boot                   Wed Jul 13 09:29
reboot    system boot                   Tue Jul 12 10:07
reboot    system boot                   Tue Jun 28 09:46
reboot    system boot                   Tue Jun 14 09:08

Does anyone know how I can get the year to display. If not the date and times show the most recent at the top. Does anyone have a script that will look at the month and time and put in the year based on seeing something like Jun occurring again after Jul when viewing the output  or is there a file or a command that will provide me with information on reboots that include year.

Thanks for your help
0
Comment
Question by:bradd138
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
9 Comments
 

Author Comment

by:bradd138
ID: 16929498
Sorry for the typo in the title.  Using the last command not lat.
0
 
LVL 38

Expert Comment

by:yuzh
ID: 16931339
last command on Solaris systems doesn't report the year included in its records,

please have a look at the following doc for workarounds:
http://www.itworld.com/nl/unix_insider/03312005/pf_index.html

other tools:
http://www.boran.com/security/sp/solaris/
0
 

Author Comment

by:bradd138
ID: 16943417
Thanks for the help yuzh but I couldn't seen to get the unpack commands to work correctly. Had had trouble with the stucture part recommend in the
http://www.oreilly.com/catalog/perlsysadm/chapter/ch09.html . I brought back information the field size weren't correct so it was hard to work with.

I put together the below pearl script that although it is not very elegant since I rarely code in pearl it appears to work.

#!/usr/bin/perl
# Bradd Baldwin
# Program to add year to last reboot

system("last | grep reboot | awk '{print \$1,\$2,\$3,\$4,\$5,\$6,\$7}' > last.txt");
open(MYFILE, "last.txt") || die "opening last.txt: $!";
@LAST_REBOOT=<MYFILE>;
close(MYFILE);
$month=0;
$year="2006";

$current_month=`date +"%m"`;#+%m-%d-%y`;
chomp($current_month);
print "$current_month test\n\n";

foreach $LAST_REBOOT (@LAST_REBOOT) {
        @fields=split(/ /, $LAST_REBOOT);
                $check_month=join(' ',@fields[4]);

        if ($check_month eq "Jan") {
                $month=1;
                if ($current_month < $month) {
                        $year=$year-1 ;
                        }
        }
        $bradd=test;
        if ($check_month eq "Feb") {
                $month=2;
                if ($current_month < $month) {
                        $year=$year-1 ;
                        }
        }
        if ($check_month eq "Mar") {
                $month=3;
                if ($current_month < $month) {
                        $year=$year-1 ;
                        }
        }
        if ($check_month eq "Apr") {
                $month=4;
                if ($current_month < $month) {
                        $year=$year-1 ;
                        }
        }
        if ($check_month eq "May") {
                $month=5;
                if ($current_month < $month) {
                        $year=$year-1 ;
                        }
        }
        if ($check_month eq "Jun") {
                $month=6;
                if ($current_month < $month) {
                        $year=$year-1 ;
                        }
        }
        if ($check_month eq "Jul") {
                $month=7;
                if ($current_month < $month) {
                        $year=$year-1 ;
                        }
        }
        if ($check_month eq "Aug") {
                $month=8;
                if ($current_month < $month) {
                        $year=$year-1 ;
                        }
        }
        if ($check_month eq "Sep") {
                $month=9;
                if ($current_month < $month) {
                        $year=$year-1 ;
                        }
        }
        if ($check_month eq "Oct") {
                $month=10;
                if ($current_month < $month) {
                        $year=$year-1 ;
                        }
        }
        if ($check_month eq "Nov") {
                $month=11;
                if ($current_month < $month) {
                        $year=$year-1 ;
                                }
        }
        if ($check_month eq "Dec") {
                $month=12;
                if ($current_month < $month) {
                        $year=$year-1 ;
                                }
        }
        if ($month eq $month) {
                $DISPLAY_INFO=join(' ',@fields[0,1,2,3,4,5,6]);
        chomp($DISPLAY_INFO);
        print "$DISPLAY_INFO $year\n";
        }
        $current_month=$month;
}
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 38

Expert Comment

by:yuzh
ID: 16948704
>but I couldn't seen to get the unpack commands to work correctly.
I'm not a perl guru, but I think the script in:
http://www.oreilly.com/catalog/perlsysadm/chapter/ch09.html 

and you can modify it as in:
http://www.itworld.com/nl/unix_insider/03312005/pf_index.html

Anyway, you can use your own version of the script if you are happy with it.
you can modify:
   grep reboot
to:
   grep $1
   so that your can get the infor for a login name or reboot as well.


0
 

Author Comment

by:bradd138
ID: 16954207
The perl script in Oreilly bring back the info directly form last which does not incule the year. My perl script has a problem if the first reboot comes in a year prior to the one we are currently in. This is also a problem for finding out years for when a person last logged in.  I would prefer to use the unpack script but it didn't work because the format of my wtmpx file does not match the struct utmp they provide. The code works it just brings back parts of the fields and not the ones I am looking for.  

From Oreilly page
"As we've shown, the format of the wtmp file differs from Unix variant to Unix variant. On top of this, a vendor can change the format of wtmp between OS releases, rendering your perfectly good unpack( ) template invalid. "

does anyone know the format of the wtmpx file on Solaris starting with version 5.6 and going to 5.9
 
0
 
LVL 38

Accepted Solution

by:
yuzh earned 1400 total points
ID: 16956519
>>does anyone know the format of the wtmpx file on Solaris starting with version 5.6 and going to 5.9

Please have a look at   /usr/include/utmpx.h for wtmp format , also have
a look at this doc:
http://www.sdsc.edu/~victor/acct.html
0
 

Author Comment

by:bradd138
ID: 16969273
Thanks for all your help yuzh I finally found the right unpack format and this works.

#!/usr/bin/perl
$template = "A32 A4 A32 l s s2 x2 l2 l x20 s A257 x";
# determine the size of a record
$recordsize = length(pack($template,(  )));
$recordsize = length(pack($template,(  )));
# open the file
open(WTMP,"/var/adm/wtmpx") or die "Unable to open wtmpx:$!\n";

# read through it one record at a time
while (read(WTMP,$record,$recordsize)) {
    ($ut_user,$ut_id,$ut_line,$ut_pid,$ut_type,$ut_e_termination,
     $ut_e_exit,$tv_sec,$tv_usec,$ut_session,$ut_syslen,$ut_host)=
       unpack($template,$record);

    if ($ut_line eq "system boot"){
        print "rebooted ".scalar localtime($tv_sec)."\n";
        $reboots++;
    }
}

close(WTMP);
print "Total reboots: $reboots\n";

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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, 8 hours left to enroll

770 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