Unix Shell - writing system boot message onto (test) wtmpx file using perl

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > October 2005 > writing system boot message onto (test) wtmpx file using perl





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author writing system boot message onto (test) wtmpx file using perl
Nikhil

2005-10-30, 7:48 am

Hello friends

I am currently trying to write a "system boot" message onto a test
wtmpx kind of file in PERL in this way..

#####code
#!/usr/bin/perl
sub get_boottime(){
my $k_module = "unix:::boot_time";
my $boott = `kstat -p $k_module`;
$boott = (split(/\t/,$boott))[1];
$boott =~ s/^\s+//g;
$boott =~ s/\s+$//g;
return $boott;
}

my $ut_template = 'A32 A4 A32 l s s2 x2 l2 l x20 s A257 x';
my $ut_file_write = "/u/me//pl_wtmpx";
my $ut_user = "reboot";
my $ut_ut_id = "";
my $ut_line = "system boot";my $ut_pid = "";
my $ut_type = 2;
my $ut_exit_e_termination = "";
my $ut_exit_e_exit = "";
my $ut_timeval = get_boottime();
my $ut_pad = "";
my $ut_session = "";
my ($ut_host, $ut_syslen) = "";

my_write_boottime();


sub my_write_boottime {
@msg_string =
($ut_user,$ut_ut_id,$ut_line,$ut_pid,$ut
_type,$ut_exit_e_termination,$ut_exit_e_
exit,$ut_timeval,$ut_pad,$ut_session,$ut
_syslen,$ut_host);
$boot_record = pack($ut_template, @msg_string);
open(WTMP_H,">$ut_file_write") || die "Unable to open
$ut_file_write : $! \n";
print WTMP_H $boot_record;
close(WTMP_H);
}


################



here is the scenario:

on solaris 10 (x86):

==============

myprompt$ > PERL writebootmsg.pl

myprompt$ > last -f "/u/me//pl_wtmpx"

reboot system boot Thu Oct 20 15:19 - 05:30
(14:10)

wtmp begins Thu Oct 20 15:19


************but when I search for "system boot" message , it gives
nothing*******

myprompt$ > last "system boot" -f "/u/me//pl_wtmpx"

wtmp begins Thu Oct 20 15:19




On Solaris 8 (sparc) :

===================

myprompt$ > PERL writebootmsg.pl

myprompt$ > last -f "/u/me//pl_wtmpx"

reboot system boot Sat Jul 23 17:50 - 05:30
(11:39)

wtmp begins Sat Jul 23 17:50


**************but again when I search for "system boot" message, it
gives nothing**************

myprompt$ > last "system boot" -f ~/temp/wtmpcheck/pl_wtmpx

wtmp begins Sat Jul 23 17:50




can someone please suggest where is that I am going wrong in writing
the record on to test wtmpx file.


and more small question, how can we get to know whether the wtmpx/utmpx
file is corrupted ?

Thanks,

Nikhil

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com