version 1.13, 2005/12/30 01:02:41 |
version 1.34, 2007/02/07 23:24:39 |
|
|
#!/usr/bin/perl
|
#!/usr/bin/perl |
# $RedRiver: update_trango.pl,v 1.12 2005/12/29 18:41:17 andrew Exp $
|
# $RedRiver: update_trango.pl,v 1.33 2007/02/07 22:07:35 andrew Exp $ |
########################################################################
|
######################################################################## |
# update_trango.pl *** Updates trango foxes with a new firmware
|
# update_trango.pl *** Updates trango hosts with a new firmware |
#
|
# |
# 2005.11.15 #*#*# andrew fresh <andrew@mad-techies.org>
|
# 2005.11.15 #*#*# andrew fresh <andrew@mad-techies.org> |
########################################################################
|
######################################################################## |
use strict;
|
# Copyright (C) 2005, 2006, 2007 by Andrew Fresh |
use warnings;
|
# |
|
# This program is free software; you can redistribute it and/or modify |
use Net::TFTP;
|
# it under the same terms as Perl itself. |
use YAML;
|
######################################################################## |
use lib '.';
|
use strict; |
use Net::Telnet::Trango;
|
use warnings; |
|
|
my $config_file = shift || 'update_trango.conf';
|
use YAML qw/ LoadFile /; |
my $max_tries = 3;
|
use Net::TFTP; |
|
use Net::Telnet::Trango; |
|
|
|
my $config_file = shift || 'update_trango.yaml'; |
my $l = Mylogger->new( { log_prefix => 'UT' } );
|
my $max_tries = 3; |
|
|
|
my $l = Mylogger->new( { log_prefix => 'UT' } ); |
$l->sp("Reading config file '$config_file'");
|
|
my $conf = read_conf($config_file);
|
$l->sp("Reading config file '$config_file'"); |
|
my $conf = LoadFile($config_file); |
$l->sp(" Hardware Type: $conf->{'type'}");
|
|
$l->sp(" File Name: $conf->{'file_name'}");
|
my $hosts; |
$l->sp(" File Size: $conf->{'file_size'}");
|
if (@ARGV) { |
$l->sp(" File Checksum: $conf->{'file_cksum'}");
|
@{$hosts} = map { { name => $_, group => 'Trango-Client' } } @ARGV; |
$l->sp(" FW Version: $conf->{'ver'}");
|
} |
$l->sp(" FW Checksum: $conf->{'cksum'}");
|
else { |
$l->sp("");
|
$hosts = parse_hosts( $conf->{hosts} ); |
|
} |
|
|
|
#@{ $hosts } = grep { $_->{name} eq '10.100.7.2' } @{ $hosts }; |
|
|
|
my $global_tries = $max_tries * 2; |
|
while ( $global_tries > 0 ) { |
foreach my $fox (@{ $conf->{'ips'} }) {
|
$global_tries--; |
$l->sp("Updating: $fox");
|
my $processed = 0; |
|
|
## Connect and login.
|
foreach my $host ( @{$hosts} ) { |
my $t = new Net::Telnet::Trango ({
|
|
Host => $fox,
|
if ( !exists $host->{retry} ) { |
Timeout => 5,
|
$host->{tries} = 0; |
Errmode => 'return',
|
$host->{retry} = 1; |
}) or die "Couldn't make new connection: $!";
|
} |
|
|
$l->p("Connecting to $fox");
|
if ( $host->{tries} >= $max_tries ) { |
unless ($t->open) {
|
$host->{retry} = 0; |
$l->sp("Error connecting: $!");
|
} |
next;
|
|
}
|
if ( $host->{retry} <= 0 ) { |
|
next; |
if ($t->host_type ne $conf->{'type'}) {
|
} |
$l->sp("Wrong type of unit ('$t->host_type' should be '$conf->{'type'}')");
|
|
$t->close;
|
$host->{tries}++; |
next;
|
$processed++; |
}
|
|
|
$l->sp(""); |
if ($t->firmware_version eq $conf->{'ver'}) {
|
$l->sp("Checking: $host->{name} (try $host->{tries})"); |
$l->sp("Already up to date with firmware version '$t->firmware_version'");
|
my $needs_reboot = 0; |
$t->close;
|
|
next;
|
## Connect and login. |
}
|
my $t = new Net::Telnet::Trango( |
|
Timeout => 5, |
$l->p("Logging in");
|
Errmode => 'return', |
$t->login($conf->{'password'}) || die "Couldn't login: $!";
|
) or die "Couldn't make new connection: $!"; |
|
$l->p("Connecting to $host->{name}"); |
$l->p("Sending commands");
|
unless ( $t->open( $host->{name} ) ) { |
## Send commands
|
$l->sp("Error connecting: $!"); |
print Dump $t->login_banner;
|
next; |
print Dump $t->sysinfo;
|
} |
print Dump $t->last_lines;
|
|
print Dump $t->ver();
|
my $password = $host->{Telnet_Password} || $conf->{general}->{password}; |
print Dump $t->tftpd();
|
|
print Dump $t->enable_tftpd();
|
$l->p("Logging in"); |
print Dump [ "Exit", $t->exit ];
|
$t->login($password); |
print Dump $t->tftpd();
|
unless ($t->logged_in) { |
print Dump $t->disable_tftpd();
|
$l->p('Failed!'); |
print Dump $t->tftpd();
|
$t->close; |
#if ( upload($t, $conf->{'file_name'}) ) {
|
next; |
# $l->p("Rebooting");
|
} |
# $t->reboot;
|
|
#} else {
|
$l->sp("Getting sudb"); |
$l->p("Exiting");
|
my $sudb = $t->sudb_view; |
$t->exit;
|
if ($sudb) { |
#}
|
foreach my $su (@{ $sudb }) { |
|
$l->p("Getting su info $su->{suid}"); |
$l->sp("");
|
my $su_info = $t->su_info( $su->{suid} ); |
}
|
if ($su_info->{ip}) { |
|
if (grep { $_->{name} eq $su_info->{'ip'} } @{ $hosts }) { |
sub upload
|
$l->p("Already have $su_info->{ip}"); |
{
|
next; |
my $t = shift;
|
} |
my $file = shift;
|
$l->sp("Adding host $su_info->{ip}"); |
|
my $new_host = { |
my $ver = $t->ver;
|
password => $host->{password}, |
$l->p("Current version '$ver->{'Firmware Version'}'");
|
name => $su_info->{ip}, |
|
remarks => $su_info->{remarks}, |
if (
|
}; |
$ver->{'Firmware Version'} eq $conf->{'ver'} &&
|
push @{ $hosts }, $new_host; |
$ver->{'Firmware Checksum'} eq $conf->{'cksum'}
|
} else { |
) {
|
$l->sp("Couldn't get su info for $su->{suid}"); |
$l->sp("Already updated!");
|
$l->sp("ERR: " . $t->last_error); |
return 1;
|
} |
}
|
} |
|
} |
my $try = 0;
|
|
while (1) {
|
foreach my $firmware_type ( 'Firmware', 'FPGA' ) { |
if ($try >= $max_tries) {
|
|
$l->sp("Couldn't update in $max_tries tries!");
|
if ( !exists $conf->{$firmware_type} ) { |
return undef;
|
$l->s("No configs for '$firmware_type'"); |
}
|
next; |
$try++;
|
} |
|
|
#sysinfo($self->{'_host'});
|
my $host_type = $t->host_type; |
|
if ( $firmware_type eq 'FPGA' ) { |
$l->p("Enabling TFTPd");
|
$host_type =~ s/\s.*$//; |
$t->enable_tftpd || die "Couldn't enable tftpd";
|
} |
|
|
$l->p("Uploading file ($file)");
|
if ( !exists $conf->{$firmware_type}->{$host_type} ) { |
# use tftp to push the file up
|
$l->sp("No '$firmware_type' config for type $host_type"); |
my $tftp = Net::TFTP->new($t->Host, Mode => 'octet');
|
next; |
|
} |
$tftp->put($file, $file)
|
|
or die "Error uploading: " . $tftp->error;
|
if ( $firmware_type eq 'Firmware' |
|
&& $t->firmware_version eq |
# waitfor some sort of output
|
$conf->{$firmware_type}->{$host_type}->{ver} ) |
# make sure it says 'Success.' otherwise error
|
{ |
#print "LAST: " . $self->lastline;
|
$l->sp("Firmware already up to date"); |
#my @lines = $self->getlines;
|
next; |
#print Dump \@lines;
|
} |
|
|
$l->p("Checking upload ($conf->{'file_cksum'})");
|
if ( !$t->logged_in ) { |
my $results = $t->tftpd;
|
$l->p("Logging in"); |
# check the 'File Length' against ???
|
$t->login($password); |
if ( $results->{'File Checksum'} ne $conf->{'file_cksum'}) {
|
unless ($t->logged_in) { |
$l->sp(
|
$l->p('Failed!'); |
"File checksum '" . $results->{'File Checksum'} .
|
$t->close; |
"does not match config file '" . $conf->{'file_cksum'} . "'!"
|
last; |
);
|
} |
next;
|
} |
}
|
|
$l->p("File checksum matches . . . ");
|
foreach my $k ( keys %{ $conf->{general} } ) { |
|
$conf->{$firmware_type}->{$host_type}->{$k} ||= |
if ($results->{'File Length'} !~ /^$conf->{'file_size'} bytes/) {
|
$conf->{general}->{$k}; |
$l->sp(
|
} |
"File length '" . $results->{'File Length'} .
|
$conf->{$firmware_type}->{$host_type}->{firmware_type} ||= |
"does not match config file '" . $conf->{'file_size'} . " bytes'!"
|
$firmware_type; |
);
|
$conf->{$firmware_type}->{$host_type}->{type} = $host_type; |
next;
|
|
}
|
$l->sp("$host_type $firmware_type"); |
$l->p("File length matches . . . ");
|
## Send commands |
|
my $rc = upload( $t, $conf->{$firmware_type}->{$host_type} ); |
if ( uc($results->{'File Name'}) ne uc($conf->{'file_name'}) ) {
|
if ($rc) { |
$l->sp(
|
$l->sp("Successfull!"); |
"File name '" . $results->{'File Name'} .
|
$host->{retry}--; |
"' does not match config file '" . $conf->{'file_name'} . "'!"
|
$needs_reboot = 1; |
);
|
} |
next;
|
elsif ( defined $rc ) { |
}
|
$l->sp("Already up to date"); |
$l->p("File name matches . . . ");
|
$host->{retry}--; |
|
} |
$l->p("Updating flash (new checksum '$conf->{'cksum'}')");
|
else { |
unless ($results = $t->updateflash(
|
$l->sp("Failed! - Bye $host->{name}"); |
args => 'mainimage ' . $ver->{'Firmware Checksum'} .
|
$l->e("Error updating $firmware_type on $host->{name}" . |
' ' . $conf->{'cksum'},
|
"(try $host->{tries})"); |
Timeout => 90,
|
$t->bye; |
) ) {
|
# don't try any other firmware, don't want to reboot |
$l->sp("Couldn't update flash: $!");
|
last; |
next;
|
} |
}
|
|
|
} |
unless (
|
|
defined $results->{'Checksum'} &&
|
if ($needs_reboot) { |
$results->{'Checksum'} eq $conf->{'cksum'}
|
$l->sp("Rebooting $host->{name}"); |
) {
|
$t->reboot; |
$l->sp("Saved checksum does not match config file!");
|
} |
next;
|
else { |
}
|
$l->sp("Bye $host->{name}"); |
$l->p("Uploaded checksum ($results->{'Checksum'}) " .
|
$t->bye(); |
"matches ($conf->{'cksum'})");
|
} |
|
} |
$l->sp("Successfully updated!");
|
|
return 1;
|
if ( !$processed ) { |
}
|
$l->sp(""); |
}
|
$l->sp("Finished. No more hosts."); |
|
last; |
sub read_conf
|
} |
{
|
} |
my $file = shift;
|
|
my %conf;
|
sub upload { |
my $in_ip_list = 0;
|
my $t = shift; |
open my $fh, $file or die "Couldn't open file $file: $!";
|
my $conf = shift; |
while (<$fh>) {
|
|
chomp;
|
my $file = $conf->{firmware_path} . '/' . $conf->{file_name}; |
next if /^#/;
|
|
next if /^$/;
|
my $fw_type = $conf->{firmware_type}; |
if ($in_ip_list) {
|
|
s/\s+//g; # Whitespace is a no no
|
my $ver = $t->ver; |
|
|
if (/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)(\d{1,3})-(\d{1,3})/) {
|
if ( |
push @{ $conf{'ips'} }, $1 . $_ for ($2..$3);
|
!( |
} else {
|
$ver->{ $fw_type . ' Version' } && $ver->{ $fw_type . ' Checksum' } |
push @{ $conf{'ips'} }, $_;
|
) |
}
|
) |
} else {
|
{ |
my ($key, $val) = split /\s+/, $_, 2;
|
$l->sp("Error getting current version numbers"); |
|
return; |
if (lc($key) eq 'ips') {
|
} |
$in_ip_list = 1;
|
|
next;
|
if ( $ver->{ $fw_type . ' Version' } eq $conf->{'ver'} |
}
|
&& $ver->{ $fw_type . ' Checksum' } eq $conf->{'cksum'} ) |
|
{ |
$key =~ s/^\s+//;
|
return 0; |
$key =~ s/\s+$//;
|
} |
$val =~ s/^\s+//;
|
|
$val =~ s/\s+$//;
|
$l->sp("Updating $fw_type"); |
|
$l->sp("Config information:"); |
$conf{ lc($key) } = $val;
|
$l->sp(" Hardware Type: $conf->{'type'}"); |
}
|
$l->sp(" File Name: $conf->{'file_name'}"); |
}
|
$l->sp(" File Size: $conf->{'file_size'}"); |
close $fh;
|
$l->sp(" File Checksum: $conf->{'file_cksum'}"); |
|
$l->sp(" Conf Version: $conf->{'ver'}"); |
#print Dump \%conf;
|
$l->sp(" Cur Version: $ver->{$fw_type . ' Version'}"); |
foreach (
|
$l->sp(" Conf Checksum: $conf->{'cksum'}"); |
'password',
|
$l->sp(" Cur Checksum: $ver->{$fw_type . ' Checksum'}"); |
'file_name', 'file_size', 'file_cksum',
|
|
'ver', 'cksum', 'ips',
|
my $try = 0; |
) {
|
while (1) { |
die "No $_ specified in config file!"
|
if ( $try >= $max_tries ) { |
if (not exists $conf{$_});
|
$l->sp("Couldn't update in $max_tries tries!"); |
}
|
return; |
|
} |
#print Dump \%conf;
|
$try++; |
#exit;
|
|
return \%conf;
|
$l->p("Enabling TFTPd"); |
}
|
unless ( $t->enable_tftpd ) { |
|
$l->sp("Couldn't enable tftpd"); |
package Mylogger;
|
next; |
|
} |
use Fcntl ':flock'; # import LOCK_* constants
|
|
#use YAML;
|
$l->p("Uploading file ($conf->{file_name})"); |
use constant LOG_PRINT => 128;
|
|
use constant LOG_SAVE => 64;
|
# use tftp to push the file up |
|
my $tftp = Net::TFTP->new( $t->Host, Mode => 'octet' ); |
DESTROY {
|
|
my $self = shift;
|
unless ( $tftp->put( $file, $file ) ) { |
if ($self->{'MYLOG'}) {
|
$l->sp( "Error uploading: " . $tftp->error ); |
$self->p("Closing log ($self->{'log_path'}/$self->{'log_file'})");
|
next; |
close $self->{'MYLOG'};
|
} |
}
|
|
}
|
$l->p("Checking upload ($conf->{'file_cksum'})"); |
|
my $results = $t->tftpd; |
sub new {
|
|
my $package = shift;
|
# check the 'File Length' against ??? |
my $self = shift || {};
|
if ( |
|
!( |
$self->{'base_path'} ||= '.';
|
$results->{'File Checksum'} |
$self->{'log_path'} ||= $self->{'base_path'};
|
&& $results->{'File Length'} |
$self->{'log_prefix'} ||= 'LOG';
|
&& $results->{'File Name'} |
$self->{'log_file'} ||= GetLogName(
|
) |
$self->{'log_prefix'},
|
) |
$self->{'log_path'}
|
{ |
);
|
$l->sp("Unable to get results of upload"); |
bless $self, $package;
|
next; |
}
|
} |
|
if ( $results->{'File Checksum'} ne $conf->{'file_cksum'} ) { |
sub s
|
$l->sp( "File checksum (" |
{
|
. $results->{'File Checksum'} |
my $self = shift;
|
. ") does not match config file (" |
my $m = shift;
|
. $conf->{'file_cksum'} |
return $self->mylog($m, LOG_SAVE);
|
. ")!" ); |
}
|
next; |
|
} |
sub p
|
$l->p("File checksum matches . . . "); |
{
|
|
my $self = shift;
|
if ( $results->{'File Length'} !~ /^$conf->{'file_size'} bytes/ ) { |
my $m = shift;
|
$l->sp( "File length (" |
return $self->mylog($m, LOG_PRINT);
|
. $results->{'File Length'} |
}
|
. ") does not match config file (" |
|
. $conf->{'file_size'} |
sub sp
|
. " bytes)!" ); |
{
|
next; |
my $self = shift;
|
} |
my $m = shift;
|
$l->p("File length matches . . . "); |
return $self->mylog($m, LOG_SAVE | LOG_PRINT);
|
|
}
|
if ( uc( $results->{'File Name'} ) ne uc($file) ) { |
|
$l->sp( "File name (" |
sub mylog
|
. $results->{'File Name'} |
{
|
. ") does not match config file (" |
my $self = shift;
|
. $file |
|
. ")!" ); |
my $thing = shift;
|
next; |
chomp $thing;
|
} |
|
$l->p("File name matches . . . "); |
my $which = shift;
|
|
|
my $image_type = 'mainimage'; |
my $MYLOG;
|
if ( $fw_type eq 'FPGA' ) { |
if ($which & LOG_PRINT) {
|
$image_type = 'fpgaimage'; |
print $thing, "\n";
|
} |
}
|
$l->p("Updating $image_type (new checksum '$conf->{'cksum'}')"); |
|
unless ( |
if ($which & LOG_SAVE) {
|
$results = $t->updateflash( |
if ($self->{'MYLOG'}) {
|
args => $image_type . ' ' |
$MYLOG = $self->{'MYLOG'};
|
. $ver->{ $fw_type . ' Checksum' } . ' ' |
} else {
|
. $conf->{'cksum'}, |
unless ($MYLOG) {
|
Timeout => 90, |
open ($MYLOG, '>>', $self->{'log_path'} . '/' . $self->{'log_file'})
|
) |
or die "Couldn't open logfile!\n";
|
) |
my $ofh = select $MYLOG;
|
{ |
$|=1;
|
$l->sp("Couldn't update flash: $!"); |
select $ofh;
|
next; |
$self->{'MYLOG'} = $MYLOG;
|
} |
|
|
$self->p("Opened log ($self->{'log_path'}/$self->{'log_file'})");
|
unless ( defined $results->{'Checksum'} |
}
|
&& $results->{'Checksum'} eq $conf->{'cksum'} ) |
}
|
{ |
flock($MYLOG, LOCK_EX);
|
$l->sp( "Saved checksum " |
print $MYLOG (scalar gmtime), "\t", $thing, "\n"
|
. $results->{'Checksum'} |
or die "Couldn't print to MYLOG: $!";
|
. " does not match config file " |
flock($MYLOG, LOCK_UN);
|
. $conf->{'cksum'} |
}
|
. "!" ); |
}
|
next; |
|
} |
sub GetLogName
|
|
{
|
$l->p("$fw_type saved checksum matches . . . "); |
my $prefix = shift || die "Invalid prefix passed for log";
|
|
|
return 1; |
my $logdate = GetLogDate();
|
} |
my $logver = 0;
|
} |
my $logname;
|
|
|
sub parse_hosts { |
do {
|
my $src = shift; |
$logname = $prefix . $logdate . sprintf("%02d", $logver) . '.log';
|
|
$logver++;
|
my @hosts; |
} until (not -e $logname);
|
foreach my $h ( @{$src} ) { |
|
if ( $h->{name} =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)(\d{1,3})-(\d{1,3})/ ) |
return $logname;
|
{ |
}
|
for ( $2 .. $3 ) { |
|
my %cur_host; |
sub GetLogDate
|
foreach my $k ( keys %{$h} ) { |
{
|
$cur_host{$k} = $h->{$k}; |
my ($sec,$min,$hour,$mday,$mon,$year,,,) = localtime();
|
} |
|
$cur_host{name} = $1 . $_; |
$mon++;
|
if ( !grep { $cur_host{name} eq $h->{name} } @hosts ) { |
$year += 1900;
|
push @hosts, \%cur_host; |
|
} |
if ($min < 10) { $min = "0$min" }
|
} |
if ($sec < 10) { $sec = "0$sec" }
|
} |
if ($hour < 10) { $hour = "0$hour" }
|
else { |
if ($mday < 10) { $mday = "0$mday" }
|
push @hosts, $h; |
if ($mon < 10) { $mon = "0$mon" }
|
} |
|
} |
my $time = $year . $mon . $mday;
|
|
|
return \@hosts; |
return $time;
|
} |
}
|
|
|
package Mylogger; |
|
|
|
use Fcntl ':flock'; # import LOCK_* constants |
|
|
|
#use YAML; |
|
use constant LOG_PRINT => 128; |
|
use constant LOG_SAVE => 64; |
|
use constant LOG_ERR => 1; |
|
|
|
DESTROY { |
|
my $self = shift; |
|
if ( $self->{'MYLOG'} ) { |
|
$self->p("Closing log ($self->{'log_path'}/$self->{'log_file'})"); |
|
close $self->{'MYLOG'}; |
|
} |
|
} |
|
|
|
sub new { |
|
my $package = shift; |
|
my $self = shift || {}; |
|
|
|
$self->{'base_path'} ||= '.'; |
|
$self->{'log_path'} ||= $self->{'base_path'}; |
|
$self->{'log_prefix'} ||= 'LOG'; |
|
$self->{'log_file'} ||= |
|
GetLogName( $self->{'log_prefix'}, $self->{'log_path'} ); |
|
bless $self, $package; |
|
} |
|
|
|
sub s { |
|
my $self = shift; |
|
my $m = shift; |
|
return $self->mylog( $m, LOG_SAVE ); |
|
} |
|
|
|
sub p { |
|
my $self = shift; |
|
my $m = shift; |
|
return $self->mylog( $m, LOG_PRINT ); |
|
} |
|
|
|
sub sp { |
|
my $self = shift; |
|
my $m = shift; |
|
return $self->mylog( $m, LOG_SAVE | LOG_PRINT ); |
|
} |
|
|
|
sub e { |
|
my $self = shift; |
|
my $m = shift; |
|
return $self->mylog( $m, LOG_ERR ); |
|
} |
|
|
|
sub mylog { |
|
my $self = shift; |
|
|
|
my $thing = shift; |
|
chomp $thing; |
|
|
|
my $which = shift; |
|
|
|
my $MYLOG; |
|
if ( $which & LOG_PRINT ) { |
|
print $thing, "\n"; |
|
} |
|
|
|
if ( $which & LOG_SAVE ) { |
|
if ( $self->{'MYLOG'} ) { |
|
$MYLOG = $self->{'MYLOG'}; |
|
} |
|
else { |
|
unless ($MYLOG) { |
|
open( $MYLOG, '>>', |
|
$self->{'log_path'} . '/' . $self->{'log_file'} ) |
|
or die "Couldn't open logfile!\n"; |
|
my $ofh = select $MYLOG; |
|
$| = 1; |
|
select $ofh; |
|
$self->{'MYLOG'} = $MYLOG; |
|
|
|
$self->p( |
|
"Opened log ($self->{'log_path'}/$self->{'log_file'})"); |
|
} |
|
} |
|
flock( $MYLOG, LOCK_EX ); |
|
print $MYLOG ( scalar gmtime ), "\t", $thing, "\n" |
|
or die "Couldn't print to MYLOG: $!"; |
|
flock( $MYLOG, LOCK_UN ); |
|
} |
|
|
|
if ( $which & LOG_ERR ) { |
|
# XXX Could tie in here to handle some sort of notifications. |
|
print STDERR $thing, "\n"; |
|
} |
|
} |
|
|
|
sub GetLogName { |
|
my $prefix = shift || die "Invalid prefix passed for log"; |
|
|
|
my $logdate = GetLogDate(); |
|
my $logver = 0; |
|
my $logname; |
|
|
|
do { |
|
$logname = $prefix . $logdate . sprintf( "%02d", $logver ) . '.log'; |
|
$logver++; |
|
} until ( not -e $logname ); |
|
|
|
return $logname; |
|
} |
|
|
|
sub GetLogDate { |
|
my ( $sec, $min, $hour, $mday, $mon, $year,,, ) = localtime(); |
|
|
|
$mon++; |
|
$year += 1900; |
|
|
|
if ( $min < 10 ) { $min = "0$min" } |
|
if ( $sec < 10 ) { $sec = "0$sec" } |
|
if ( $hour < 10 ) { $hour = "0$hour" } |
|
if ( $mday < 10 ) { $mday = "0$mday" } |
|
if ( $mon < 10 ) { $mon = "0$mon" } |
|
|
|
my $time = $year . $mon . $mday; |
|
|
|
return $time; |
|
} |