Solved

Need to display YEAR data from Solaris wtmpx file contents

Posted on 2007-03-21
4
842 Views
Last Modified: 2013-12-27
I need a Solaris solution to produce "last" output (run against wtmpx) that displays YEAR data as well as month, day & time. Standard "last" output does not include YEAR data. Can someone help? Thanks!
0
Comment
Question by:pzxkys
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 250 total points
Comment Utility
The following script may serve your needs.  It doesn't provide all the options of the 'last' command, but it wouldn't be too difficult to change it.

#!/usr/bin/perl
use strict;

my $template = "A32 A4 A32 l s s2 x2 l2 l x20 s A257 x";
my $recordsize = length(pack($template,()));
open WTMPX,"/var/adm/wtmpx" or die "Unable to open wtmpx:$!\n";

my $record;

while (read(WTMPX,$record,$recordsize)) {
  my ($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);
  printf("%-9s %10s %s\n",$ut_user, $ut_line, scalar localtime($tv_sec)) if ($ut_user =~ /^[a-z]/);
}

close WTMPX;
0
 
LVL 38

Expert Comment

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

please have a look at the answer in http:Q_21890379.html  for workarounds.
0
 

Author Comment

by:pzxkys
Comment Utility
I believe Tintin's answer solves my problem. Just one follow-up question please. Is Perl a standard piece of all Solaris releases now? I see it on Solaris 8 , 9 and Solaris 10 systems that I examined this morning. Not sure if we have any Solaris 7 systems around ... but we may ...
0
 

Author Comment

by:pzxkys
Comment Utility
Thanks to Tintin and Vuzh for the response! I answered my own follow-up question. I found some doc that says "Starting with Solaris 8, perl5.00503 (or higher) is supplied with the operating system". Thanks again!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now