[BACK]Return to update_trango.pl CVS log [TXT][DIR] Up to [local] / trango / Net-Telnet-Trango / scripts

Diff for /trango/Net-Telnet-Trango/scripts/update_trango.pl between version 1.10 and 1.24

version 1.10, 2005/12/21 01:17:06 version 1.24, 2007/02/02 16:29:58
Line 1 
Line 1 
 #!/usr/bin/perl  #!/usr/bin/perl
 # $RedRiver: update_trango.pl,v 1.9 2005/11/18 19:17:12 andrew Exp $  # $RedRiver: update_trango.pl,v 1.23 2007/02/01 18:44:30 andrew Exp $
 ########################################################################  ########################################################################
 # update_trango.pl *** Updates trango foxes with a new firmware  # update_trango.pl *** Updates trango foxes with a new firmware
 #  #
 # 2005.11.15 #*#*# andrew fresh <andrew@mad-techies.org>  # 2005.11.15 #*#*# andrew fresh <andrew@mad-techies.org>
 ########################################################################  ########################################################################
 use strict;  use strict;
 use warnings;  use warnings;
   
 use Net::TFTP;  use YAML qw/ LoadFile /;
   use Net::TFTP;
 my $config_file = shift || 'update_trango.conf';  use lib '.';
 my $max_tries = 3;  use Net::Telnet::Trango;
   
   my $config_file = shift || 'update_trango.yaml';
   my $max_tries = 3;
 my $l = Mylogger->new( { log_prefix => 'UT' } );  
   my $l = Mylogger->new( { log_prefix => 'UT' } );
   
 $l->sp("Reading config file '$config_file'");  $l->sp("Reading config file '$config_file'");
 my $conf = read_conf($config_file);  my $conf = LoadFile($config_file);
   
 $l->sp("  Hardware Type: $conf->{'type'}");  my @foxes = (
 $l->sp("  File Name:     $conf->{'file_name'}");  '10.100.1.2',
 $l->sp("  File Size:     $conf->{'file_size'}");  '10.100.2.2',
 $l->sp("  File Checksum: $conf->{'file_cksum'}");  '10.100.3.2',
 $l->sp("  FW Version:    $conf->{'ver'}");  '10.100.3.3',
 $l->sp("  FW Checksum:   $conf->{'cksum'}");  '10.100.3.4',
 $l->sp("");  '10.100.3.8',
   '10.100.4.2',
   '10.100.60.5',
   '10.100.80.5',
   '10.100.150.5',
   '10.100.5.2',
   '10.100.6.2',
 foreach my $fox (@{ $conf->{'ips'} }) {  '10.100.7.2',
   $l->sp("Updating: $fox");  '10.100.8.2',
   '10.100.9.2',
   ## Connect and login.  '10.100.21.2',
   my $t = new Trango::Telnet ({  '10.100.22.2',
     Host    => $fox,  '10.100.23.2',
     Timeout => 5,  '10.100.32.2',
   });  '10.100.33.2',
   '10.100.41.2',
   $l->p("Connecting to $fox");  '10.100.51.2',
   my ($type, $version) = $t->connect();  '10.100.52.2',
   '10.100.53.2',
   unless (defined $type && defined $version) {  '10.100.54.2',
     $l->sp("Error connecting!");  '10.100.61.2',
     next;  '10.100.62.2',
   }  );
   
   if ($type ne $conf->{'type'}) {  foreach my $fox (@foxes) {
     $l->sp("Wrong type of unit ('$type' should be '$conf->{'type'}')");    $l->sp("Checking: $fox");
     $t->close;    my $needs_reboot = 0;
     next;  
   }    ## Connect and login.
     my $t = new Net::Telnet::Trango (
   if ($version eq $conf->{'ver'}) {      Timeout => 5,
     $l->sp("Already up to date with firmware version '$version'");      Errmode => 'return',
     $t->close;    ) or die "Couldn't make new connection: $!";
     next;    $l->p("Connecting to $fox");
   }    unless ( $t->open($fox) ) {
       $l->sp("Error connecting: $!");
   $l->p("Logging in");      next;
   $t->login($conf->{'password'}) || die "Couldn't login: $!";    }
   
   $l->p("Sending commands");    foreach my $firmware_type ('Firmware', 'FPGA') {
   ## Send commands  
   if ( upload($t, $conf->{'file_name'}) ) {      if (! exists $conf->{$firmware_type}) {
     $l->p("Rebooting");            $l->s("No configs for '$firmware_type'");
     $t->reboot;            $t->close();
   } else {            next;
     $l->p("Exiting");          }
     $t->exit;  
   }      my $host_type = $t->host_type;
   $t->close;      if ($firmware_type eq 'FPGA') {
   $l->sp("");        $host_type =~ s/\s.*$//;
 }      }
   
 sub upload      if (! exists $conf->{$firmware_type}->{$host_type}) {
 {            $l->sp("No '$firmware_type' config for type $host_type");
   my $t    = shift;            $t->close();
   my $file = shift;            next;
           }
   $l->p("Getting current version");  
   my $ver = $t->ver;      if (! $t->logged_in) {
         $l->p("Logging in");
   if (        $t->login($conf->{general}->{'password'});
     $ver->{'Firmware Version'}  eq $conf->{'ver'} &&        unless ($t->logged_in) {
     $ver->{'Firmware Checksum'} eq $conf->{'cksum'}          $l->p('Failed!');
   ) {          $t->bye();
     $l->sp("Already updated!");          next;
     return 1;        }
   }      }
   
   my $try = 0;          foreach my $k (keys %{ $conf->{general} }) {
   while (1) {            $conf->{$firmware_type}->{$host_type}->{$k} ||= $conf->{general}->{$k};
     if ($try >= $max_tries) {      }
       $l->sp("Couldn't update in $max_tries tries!");          $conf->{$firmware_type}->{$host_type}->{firmware_type} ||= $firmware_type;
       return undef;          $conf->{$firmware_type}->{$host_type}->{type} = $host_type;
     }  
     $try++;      $l->sp("$host_type $firmware_type");
       $l->p("Sending commands");
     #sysinfo($self->{'_host'});      ## Send commands
           my $rc = upload($t, $conf->{$firmware_type}->{$host_type});
     $l->p("Enabling TFTPd");          if ($rc) {
     $t->enable_tftpd || die "Couldn't enable tftpd";        $l->sp("Successfull!");
             $needs_reboot = 1;
     $l->p("Uploading file ($file)");      } elsif (defined $rc) {
     # use tftp to push the file up            $l->sp("Already up to date");
     my $tftp = Net::TFTP->new($t->Host, Mode => 'octet');      } else {
             $l->sp("Failed");
     $tftp->put($file, $file)            $t->bye;
       or die "Error uploading: " . $tftp->error;            next;
       }
     # waitfor some sort of output  
     # make sure it says 'Success.' otherwise error    }
     #print "LAST: " . $self->lastline;  
     #my @lines = $self->getlines;    if ($needs_reboot) {
     #print Dump \@lines;      $l->sp("Rebooting $fox");
           $t->reboot;
     $l->p("Checking upload ($conf->{'file_cksum'})");    } else {
     my $results = $t->tftpd;      $l->sp("Bye $fox");
     # check the 'File Length' against ???      $t->bye();
     if ( $results->{'File Checksum'} ne $conf->{'file_cksum'}) {    }
       $l->sp(    $l->sp("");
         "File checksum '" . $results->{'File Checksum'} .  }
         "does not match config file '" . $conf->{'file_cksum'} . "'!"  
       );  sub upload
       next;  {
     }    my $t    = shift;
     $l->p("File checksum matches . . . ");    my $conf = shift;
   
     if ($results->{'File Length'}   !~ /^$conf->{'file_size'} bytes/) {    my $file = $conf->{firmware_path} . '/' . $conf->{file_name};
       $l->sp(  
         "File length '" . $results->{'File Length'} .    my $fw_type = $conf->{firmware_type};
         "does not match config file '" . $conf->{'file_size'} . " bytes'!"  
       );    my $ver = $t->ver;
       next;  
     }    if (
     $l->p("File length matches . . . ");      $ver->{$fw_type . ' Version'}  eq $conf->{'ver'} &&
       $ver->{$fw_type . ' Checksum'} eq $conf->{'cksum'}
     if ( uc($results->{'File Name'}) ne uc($conf->{'file_name'}) ) {    ) {
       $l->sp(      return 0;
         "File name '" . $results->{'File Name'} .    }
         "' does not match config file '" . $conf->{'file_name'} . "'!"  
       );    $l->sp("Config information:");
       next;    $l->sp("  Hardware Type: $conf->{'type'}");
     }    $l->sp("  File Name:     $conf->{'file_name'}");
     $l->p("File name  matches . . . ");    $l->sp("  File Size:     $conf->{'file_size'}");
     $l->sp("  File Checksum: $conf->{'file_cksum'}");
     $l->p("Updating flash (new checksum '$conf->{'cksum'}')");    $l->sp("  Conf Version:  $conf->{'ver'}");
     unless ($results = $t->updateflash(    $l->sp("  Cur  Version:  $ver->{$fw_type . ' Version'}");
       $ver->{'Firmware Checksum'}, $conf->{'cksum'}    $l->sp("  Conf Checksum: $conf->{'cksum'}");
     ) ) {    $l->sp("  Cur  Checksum: $ver->{$fw_type . ' Checksum'}");
       $l->sp("Couldn't update flash: $!");  
       next;    $l->sp("Updating");
     }    my $try = 0;
     while (1) {
     unless (      if ($try >= $max_tries) {
       defined $results->{'Checksum'} &&        $l->sp("Couldn't update in $max_tries tries!");
       $results->{'Checksum'} eq $conf->{'cksum'}        return;
     ) {      }
       $l->sp("Saved checksum does not match config file!");      $try++;
       next;  
     }      #sysinfo($self->{'_host'});
     $l->p("Uploaded checksum ($results->{'Checksum'}) " .  
           "matches ($conf->{'cksum'})");      $l->p("Enabling TFTPd");
           unless ($t->enable_tftpd) {
     $l->sp("Successfully updated!");        $l->sp("Couldn't enable tftpd");
     return 1;        next;
   }      }
 }  
       $l->p("Uploading file ($file)");
 sub read_conf      # use tftp to push the file up
 {      my $tftp = Net::TFTP->new($t->Host, Mode => 'octet');
   my $file = shift;  
   my %conf;      unless ($tftp->put($file, $file)) {
   my $in_ip_list = 0;        $l->sp("Error uploading: " . $tftp->error);
   open my $fh, $file or die "Couldn't open file $file: $!";        next;
   while (<$fh>) {      }
     chomp;  
     next if /^#/;      $l->p("Checking upload ($conf->{'file_cksum'})");
     next if /^$/;      my $results = $t->tftpd;
     if ($in_ip_list) {      # check the 'File Length' against ???
       s/\s+//g; # Whitespace is a no no      if ( $results->{'File Checksum'} ne $conf->{'file_cksum'}) {
         $l->sp(
       if (/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)(\d{1,3})-(\d{1,3})/) {          "File checksum '" . $results->{'File Checksum'} .
         push @{ $conf{'ips'} }, $1 . $_ for ($2..$3);          " does not match config file '" . $conf->{'file_cksum'} . "'!"
       } else {        );
         push @{ $conf{'ips'} }, $_;        next;
       }      }
     } else {      $l->p("File checksum matches . . . ");
       my ($key, $val) = split /\s+/, $_, 2;  
       if ($results->{'File Length'}   !~ /^$conf->{'file_size'} bytes/) {
       if (lc($key) eq 'ips') {        $l->sp(
         $in_ip_list = 1;          "File length '" . $results->{'File Length'} .
         next;          "does not match config file '" . $conf->{'file_size'} . " bytes'!"
       }        );
         next;
       $key =~ s/^\s+//;      }
       $key =~ s/\s+$//;      $l->p("File length matches . . . ");
       $val =~ s/^\s+//;  
       $val =~ s/\s+$//;      if ( uc($results->{'File Name'}) ne uc($file) ) {
         $l->sp(
       $conf{ lc($key) } = $val;          "File name '" . $results->{'File Name'} .
     }          "' does not match config file '" . $file . "'!"
   }        );
   close $fh;        next;
       }
   #print Dump \%conf;      $l->p("File name  matches . . . ");
   foreach (  
     'password',      my $image_type = 'mainimage';
     'file_name', 'file_size', 'file_cksum',      if ($fw_type eq 'FPGA') {
     'ver', 'cksum', 'ips',        $image_type = 'fpgaimage';
   ) {      }
     die "No $_ specified in config file!"      $l->p("Updating $image_type (new checksum '$conf->{'cksum'}')");
       if (not exists $conf{$_});      unless ($results = $t->updateflash(
   }        args => $image_type . ' ' . $ver->{$fw_type . ' Checksum'} .
                 ' '          . $conf->{'cksum'},
   #print Dump \%conf;        Timeout => 90,
   #exit;      ) ) {
   return \%conf;        $l->sp("Couldn't update flash: $!");
 }        next;
       }
 package Trango::Telnet;  
 use base 'Net::Telnet';      unless (
         defined $results->{'Checksum'} &&
 my %PRIVATE = (        $results->{'Checksum'} eq $conf->{'cksum'}
   connected => 0,      ) {
   logged_in => 0,        $l->sp("Saved checksum " . $results->{'Checksum'} . " does not match config file " .  $conf->{'cksum'} . "!");
 );        next;
       }
 sub new {      $l->p("Uploaded checksum ($results->{'Checksum'}) " .
   my $class = shift;            "matches ($conf->{'cksum'})");
   my $args = shift || {};  
       $l->sp("Successfully updated!");
   $args->{'Timeout'} ||= 5;      return 1;
   $args->{'Prompt'}  ||= '/#> *$/';    }
   }
   foreach my $key (keys %{ $args }) {  
     $PRIVATE{$key} = $args->{$key};  package Mylogger;
   }  
   use Fcntl ':flock'; # import LOCK_* constants
   my $self = $class->SUPER::new(%{ $args });  #use YAML;
   bless $self;  use constant LOG_PRINT => 128;
   use constant LOG_SAVE  =>  64;
   #bless $self, $package;  
   return $self;  DESTROY {
 }    my $self = shift;
     if ($self->{'MYLOG'}) {
 sub connect      $self->p("Closing log ($self->{'log_path'}/$self->{'log_file'})");
 {      close $self->{'MYLOG'};
   my $self = shift;    }
   }
   unless ( $self->open(  
       Host => $PRIVATE{'Host'},  sub new {
       Errmode => 'return',    my $package = shift;
   ) ) {    my $self = shift || {};
     $! = "Couldn't connect to $self->{'Host'}.  Connection timed out.";  
     return undef, undef;    $self->{'base_path'}  ||= '.';
   }    $self->{'log_path'}   ||= $self->{'base_path'};
   #$self->dump_log('dump.log');    $self->{'log_prefix'} ||= 'LOG';
     $self->{'log_file'}   ||= GetLogName(
   ## Login to remote host.      $self->{'log_prefix'},
   unless ($self->waitfor(      $self->{'log_path'}
     -match => '/password: ?$/i',    );
     -errmode => "return",    bless $self, $package;
   ) ) {  }
     $! = "problem connecting to host ($self->{'Host'}): " . $self->lastline;  
     return undef;  sub s
   }  {
     my $self = shift;
   $self->login_banner($self->lastline);    my $m = shift;
     return $self->mylog($m, LOG_SAVE);
   $PRIVATE{'connected'} = 1;  }
   
   return ($self->host_type, $self->firmware_version);  sub p
 }  {
     my $self = shift;
 sub login    my $m = shift;
 {    return $self->mylog($m, LOG_PRINT);
   my $self = shift;  }
   
   my $password = shift;  sub sp
   {
   $self->print($password);    my $self = shift;
   unless ($self->waitfor(    my $m = shift;
     -match => $self->prompt,    return $self->mylog($m, LOG_SAVE | LOG_PRINT);
     -errmode => "return",  }
   ) ) {  
     $! = "login ($self->{'Host'}) failed: " . $self->lastline;  sub mylog
     return undef;  {
   }    my $self = shift;
   
   $PRIVATE{'logged_in'} = 1;    my $thing = shift;
     chomp $thing;
   return 1;  
 }    my $which = shift;
   
 sub login_banner    my $MYLOG;
 {    if ($which & LOG_PRINT) {
   my $self = shift;      print $thing, "\n";
     }
   my $banner = shift || $PRIVATE{'login_banner'};  
     if ($which & LOG_SAVE) {
   my ($type, $ver) = $banner =~      if ($self->{'MYLOG'}) {
     /Welcome to Trango Broadband Wireless (.+)[\s-](\w+)$/i;        $MYLOG = $self->{'MYLOG'};
       } else {
   $self->host_type($type);        unless ($MYLOG) {
   $self->firmware_version($ver);                  open ($MYLOG, '>>', $self->{'log_path'} . '/' . $self->{'log_file'})
             or die "Couldn't open logfile!\n";
   return $banner;          my $ofh = select $MYLOG;
 }          $|=1;
           select $ofh;
 sub host_type          $self->{'MYLOG'} = $MYLOG;
 {  
   my $self = shift;          $self->p("Opened log ($self->{'log_path'}/$self->{'log_file'})");
         }
   my $type = shift || $PRIVATE{'host_type'};      }
   $PRIVATE{'host_type'} = $type;      flock($MYLOG, LOCK_EX);
       print $MYLOG (scalar gmtime), "\t", $thing, "\n"
   return $type;        or die "Couldn't print to MYLOG: $!";
 }      flock($MYLOG, LOCK_UN);
     }
 sub firmware_version  }
 {  
   my $self = shift;  sub GetLogName
   {
   my $ver = shift || $PRIVATE{'firmware_version'};    my $prefix  = shift || die "Invalid prefix passed for log";
   $PRIVATE{'firmware_version'} = $ver;  
       my $logdate = GetLogDate();
   return $ver    my $logver  = 0;
 }    my $logname;
   
 sub Host    do {
 {      $logname = $prefix . $logdate . sprintf("%02d", $logver) . '.log';
   my $self = shift;      $logver++;
       } until (not -e $logname);
   my $host = shift || $PRIVATE{'Host'};  
   $PRIVATE{'HOST'} = $host;    return $logname;
   }
   return $host;  
 }  sub GetLogDate
   {
     my ($sec,$min,$hour,$mday,$mon,$year,,,) = localtime();
 sub reboot  
 {    $mon++;
   my $self = shift;    $year += 1900;
   
   $self->print("reboot\n");    if ($min  < 10) { $min  = "0$min"  }
   $self->getline;    if ($sec  < 10) { $sec  = "0$sec"  }
     if ($hour < 10) { $hour = "0$hour" }
   return 1;    if ($mday < 10) { $mday = "0$mday" }
 }    if ($mon  < 10) { $mon  = "0$mon"  }
   
 sub exit    my $time = $year . $mon . $mday;
 {  
   my $self = shift;    return $time;
   }
   $self->print("exit\n");  
   $self->getline;  
   
   return 1;  
 }  
   
 sub ver  
 {  
   my $self = shift;  
   
   return $self->cmd('ver');  
 }  
   
 sub tftpd  
 {  
   my $self = shift;  
   
   return $self->cmd('tftpd', 'Success.');  
 }  
   
 sub sysinfo  
 {  
   my $self = shift;  
   
   return $self->cmd('sysinfo', 'Success.');  
 }  
   
 sub enable_tftpd  
 {  
   my $self = shift;  
   
   my $vals = $self->cmd('tftpd on', 'Success.');  
   
   if ($vals->{'Tftpd'} eq 'listen') {  
     return $vals;  
   } else {  
     return undef;  
   }  
 }  
   
 sub updateflash  
 {  
   my $self = shift;  
   
   my $old = shift;  
   my $new = shift;  
   
   return undef unless $new;  
   
   return $self->cmd("updateflash mainimage $old $new", 'Success.', 90);  
 }  
   
 sub cmd  
 {  
   my $self = shift;  
   
   my $string = shift;  
   my $expect_last = shift;  
   my $timeout = shift || $PRIVATE{'Timeout'};  
   
   unless (defined $string) {  
     $! = "No command passed";  
     return undef;  
   }  
   
   unless ($PRIVATE{'connected'}) {  
     $! = "Not connected";  
     return undef;  
   }  
   
   unless ($PRIVATE{'logged_in'}) {  
     $! = "Not logged in";  
     return undef;  
   }  
   
   my @lines = $self->SUPER::cmd(String => $string, Timeout => $timeout);  
   
   my $vals = _decode_lines(@lines);  
   
   unless ($expect_last) {  
     return $vals;  
   }  
   
   my $last = $self->lastline;  
   
   if ($last =~ /$expect_last$/) {  
     return $vals;  
   } else {  
     warn "Error with command ($string): $last";  
     return undef;  
   }  
 }  
   
 sub _decode_lines  
 {  
   my @lines = @_;  
   
   my %conf;  
   
   my $key = '';  
   my $val = '';  
   my $in_key = 0;  
   my $in_val = 0;  
   
   foreach my $line (@lines) {  
     my @chars = split //, $line;  
   
     my $last_key = '';  
     foreach my $c (@chars) {  
   
       if ($c eq '[' || $c eq "\r" || $c eq "\n") {  
         if ($c eq '[') {  
           $in_key = 1;  
           $in_val = 0;  
         } else {  
           $in_key = 0;  
           $in_val = 0;  
         }  
   
         if ($key) {  
           $key =~ s/^\s+//;  
           $key =~ s/\s+$//;  
   
           $val =~ s/^\s+//;  
           $val =~ s/\s+$//;  
   
           if ($key eq 'Checksum' && $last_key) {  
             # Special case for these bastids.  
             my $new = $last_key;  
             $new =~ s/\s+\S+$//;  
             $key = $new . " " . $key;  
           }  
   
           $last_key = $key;  
           $conf{$key} = $val;  
           $key = '';  
           $val = '';  
         }  
   
       } elsif ($c eq ']') {  
         $in_val = 1;  
         $in_key = 0;  
         $c = shift @chars;  
   
       } elsif ($in_key) {  
         $key .= $c;  
   
       } elsif ($in_val) {  
         $val .= $c;  
       }  
     }  
   }  
   #print Dump \%conf;  
   
   if (%conf) {  
     return \%conf;  
   } else {  
     return \@lines;  
   }  
 }  
   
   
   
 package Mylogger;  
   
 use Fcntl ':flock'; # import LOCK_* constants  
 #use YAML;  
 use constant LOG_PRINT => 128;  
 use constant LOG_SAVE  =>  64;  
   
 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 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);  
   }  
 }  
   
 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;  
 }  

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.24

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>