[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.16

version 1.10, 2005/12/21 01:17:06 version 1.16, 2007/01/08 16:49:44
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.15 2005/12/30 20:26:41 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 Net::TFTP;
   use YAML;
 my $config_file = shift || 'update_trango.conf';  use lib '.';
 my $max_tries = 3;  use Net::Telnet::Trango;
   
   my $config_file = shift || 'update_trango.conf';
   my $max_tries = 3;
 my $l = Mylogger->new( { log_prefix => 'UT' } );  
   
   
 $l->sp("Reading config file '$config_file'");  my $l = Mylogger->new( { log_prefix => 'UT' } );
 my $conf = read_conf($config_file);  
   
 $l->sp("  Hardware Type: $conf->{'type'}");  $l->sp("Reading config file '$config_file'");
 $l->sp("  File Name:     $conf->{'file_name'}");  my $conf = read_conf($config_file);
 $l->sp("  File Size:     $conf->{'file_size'}");  
 $l->sp("  File Checksum: $conf->{'file_cksum'}");  $l->sp("  Hardware Type: $conf->{'type'}");
 $l->sp("  FW Version:    $conf->{'ver'}");  $l->sp("  File Name:     $conf->{'file_name'}");
 $l->sp("  FW Checksum:   $conf->{'cksum'}");  $l->sp("  File Size:     $conf->{'file_size'}");
 $l->sp("");  $l->sp("  File Checksum: $conf->{'file_cksum'}");
   $l->sp("  FW Version:    $conf->{'ver'}");
   $l->sp("  FW Checksum:   $conf->{'cksum'}");
   $l->sp("");
   
   
   
 foreach my $fox (@{ $conf->{'ips'} }) {  
   $l->sp("Updating: $fox");  
   
   ## Connect and login.  foreach my $fox (@{ $conf->{'ips'} }) {
   my $t = new Trango::Telnet ({    $l->sp("Updating: $fox");
     Host    => $fox,  
     Timeout => 5,    ## Connect and login.
   });    my $t = new Net::Telnet::Trango (
       Timeout => 5,
   $l->p("Connecting to $fox");      Errmode => 'return',
   my ($type, $version) = $t->connect();    ) or die "Couldn't make new connection: $!";
   
   unless (defined $type && defined $version) {    $l->p("Connecting to $fox");
     $l->sp("Error connecting!");    unless ( $t->open($fox) ) {
     next;      $l->sp("Error connecting: $!");
   }      next;
     }
   if ($type ne $conf->{'type'}) {  
     $l->sp("Wrong type of unit ('$type' should be '$conf->{'type'}')");    if ($t->host_type ne $conf->{'type'}) {
     $t->close;      $l->sp("Wrong type of unit ('$t->host_type' should be '$conf->{'type'}')");
     next;      $t->close;
   }      next;
     }
   if ($version eq $conf->{'ver'}) {  
     $l->sp("Already up to date with firmware version '$version'");    if ($t->firmware_version eq $conf->{'ver'}) {
     $t->close;      $l->sp("Already up to date with firmware version '$t->firmware_version'");
     next;      $t->close;
   }      next;
     }
   $l->p("Logging in");  
   $t->login($conf->{'password'}) || die "Couldn't login: $!";    $l->p("Logging in");
     $t->login($conf->{'password'}) || die "Couldn't login: $!";
   $l->p("Sending commands");  
   ## Send commands    $l->p("Sending commands");
   if ( upload($t, $conf->{'file_name'}) ) {    ## Send commands
     $l->p("Rebooting");    #print Dump $t->login_banner;
     $t->reboot;    #print Dump $t->sysinfo;
   } else {    #print Dump $t->last_lines;
     $l->p("Exiting");    #print Dump $t->ver();
     $t->exit;    #print Dump $t->tftpd();
   }    #print Dump $t->enable_tftpd();
   $t->close;    #print Dump [ "Exit", $t->exit ];
   $l->sp("");    #print Dump $t->tftpd();
 }    #print Dump $t->disable_tftpd();
     #print Dump $t->tftpd();
 sub upload    print Dump $t->sulog(args => 5);
 {    #if ( upload($t, $conf->{'file_name'}) ) {
   my $t    = shift;    #   $l->p("Rebooting");
   my $file = shift;    #  $t->reboot;
     #} else {
   $l->p("Getting current version");      $l->p("Exiting");
   my $ver = $t->ver;      $t->exit;
     #}
   if (  
     $ver->{'Firmware Version'}  eq $conf->{'ver'} &&    $l->sp("");
     $ver->{'Firmware Checksum'} eq $conf->{'cksum'}  }
   ) {  
     $l->sp("Already updated!");  sub upload
     return 1;  {
   }    my $t    = shift;
     my $file = shift;
   my $try = 0;  
   while (1) {    my $ver = $t->ver;
     if ($try >= $max_tries) {    $l->p("Current version '$ver->{'Firmware Version'}'");
       $l->sp("Couldn't update in $max_tries tries!");  
       return undef;    if (
     }      $ver->{'Firmware Version'}  eq $conf->{'ver'} &&
     $try++;      $ver->{'Firmware Checksum'} eq $conf->{'cksum'}
     ) {
     #sysinfo($self->{'_host'});      $l->sp("Already updated!");
           return 1;
     $l->p("Enabling TFTPd");    }
     $t->enable_tftpd || die "Couldn't enable tftpd";  
     my $try = 0;
     $l->p("Uploading file ($file)");    while (1) {
     # use tftp to push the file up      if ($try >= $max_tries) {
     my $tftp = Net::TFTP->new($t->Host, Mode => 'octet');        $l->sp("Couldn't update in $max_tries tries!");
         return undef;
     $tftp->put($file, $file)      }
       or die "Error uploading: " . $tftp->error;      $try++;
   
     # waitfor some sort of output      #sysinfo($self->{'_host'});
     # make sure it says 'Success.' otherwise error  
     #print "LAST: " . $self->lastline;      $l->p("Enabling TFTPd");
     #my @lines = $self->getlines;      $t->enable_tftpd || die "Couldn't enable tftpd";
     #print Dump \@lines;  
           $l->p("Uploading file ($file)");
     $l->p("Checking upload ($conf->{'file_cksum'})");      # use tftp to push the file up
     my $results = $t->tftpd;      my $tftp = Net::TFTP->new($t->Host, Mode => 'octet');
     # check the 'File Length' against ???  
     if ( $results->{'File Checksum'} ne $conf->{'file_cksum'}) {      $tftp->put($file, $file)
       $l->sp(        or die "Error uploading: " . $tftp->error;
         "File checksum '" . $results->{'File Checksum'} .  
         "does not match config file '" . $conf->{'file_cksum'} . "'!"      # waitfor some sort of output
       );      # make sure it says 'Success.' otherwise error
       next;      #print "LAST: " . $self->lastline;
     }      #my @lines = $self->getlines;
     $l->p("File checksum matches . . . ");      #print Dump \@lines;
   
     if ($results->{'File Length'}   !~ /^$conf->{'file_size'} bytes/) {      $l->p("Checking upload ($conf->{'file_cksum'})");
       $l->sp(      my $results = $t->tftpd;
         "File length '" . $results->{'File Length'} .      # check the 'File Length' against ???
         "does not match config file '" . $conf->{'file_size'} . " bytes'!"      if ( $results->{'File Checksum'} ne $conf->{'file_cksum'}) {
       );        $l->sp(
       next;          "File checksum '" . $results->{'File Checksum'} .
     }          "does not match config file '" . $conf->{'file_cksum'} . "'!"
     $l->p("File length matches . . . ");        );
         next;
     if ( uc($results->{'File Name'}) ne uc($conf->{'file_name'}) ) {      }
       $l->sp(      $l->p("File checksum matches . . . ");
         "File name '" . $results->{'File Name'} .  
         "' does not match config file '" . $conf->{'file_name'} . "'!"      if ($results->{'File Length'}   !~ /^$conf->{'file_size'} bytes/) {
       );        $l->sp(
       next;          "File length '" . $results->{'File Length'} .
     }          "does not match config file '" . $conf->{'file_size'} . " bytes'!"
     $l->p("File name  matches . . . ");        );
         next;
     $l->p("Updating flash (new checksum '$conf->{'cksum'}')");      }
     unless ($results = $t->updateflash(      $l->p("File length matches . . . ");
       $ver->{'Firmware Checksum'}, $conf->{'cksum'}  
     ) ) {      if ( uc($results->{'File Name'}) ne uc($conf->{'file_name'}) ) {
       $l->sp("Couldn't update flash: $!");        $l->sp(
       next;          "File name '" . $results->{'File Name'} .
     }          "' does not match config file '" . $conf->{'file_name'} . "'!"
         );
     unless (        next;
       defined $results->{'Checksum'} &&      }
       $results->{'Checksum'} eq $conf->{'cksum'}      $l->p("File name  matches . . . ");
     ) {  
       $l->sp("Saved checksum does not match config file!");      $l->p("Updating flash (new checksum '$conf->{'cksum'}')");
       next;      unless ($results = $t->updateflash(
     }        args => 'mainimage ' . $ver->{'Firmware Checksum'} .
     $l->p("Uploaded checksum ($results->{'Checksum'}) " .                ' '          . $conf->{'cksum'},
           "matches ($conf->{'cksum'})");        Timeout => 90,
           ) ) {
     $l->sp("Successfully updated!");        $l->sp("Couldn't update flash: $!");
     return 1;        next;
   }      }
 }  
       unless (
 sub read_conf        defined $results->{'Checksum'} &&
 {        $results->{'Checksum'} eq $conf->{'cksum'}
   my $file = shift;      ) {
   my %conf;        $l->sp("Saved checksum does not match config file!");
   my $in_ip_list = 0;        next;
   open my $fh, $file or die "Couldn't open file $file: $!";      }
   while (<$fh>) {      $l->p("Uploaded checksum ($results->{'Checksum'}) " .
     chomp;            "matches ($conf->{'cksum'})");
     next if /^#/;  
     next if /^$/;      $l->sp("Successfully updated!");
     if ($in_ip_list) {      return 1;
       s/\s+//g; # Whitespace is a no no    }
   }
       if (/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)(\d{1,3})-(\d{1,3})/) {  
         push @{ $conf{'ips'} }, $1 . $_ for ($2..$3);  sub read_conf
       } else {  {
         push @{ $conf{'ips'} }, $_;    my $file = shift;
       }    my %conf;
     } else {    my $in_ip_list = 0;
       my ($key, $val) = split /\s+/, $_, 2;    open my $fh, $file or die "Couldn't open file $file: $!";
     while (<$fh>) {
       if (lc($key) eq 'ips') {      chomp;
         $in_ip_list = 1;      next if /^#/;
         next;      next if /^$/;
       }      if ($in_ip_list) {
         s/\s+//g; # Whitespace is a no no
       $key =~ s/^\s+//;  
       $key =~ s/\s+$//;        if (/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)(\d{1,3})-(\d{1,3})/) {
       $val =~ s/^\s+//;          push @{ $conf{'ips'} }, $1 . $_ for ($2..$3);
       $val =~ s/\s+$//;        } else {
           push @{ $conf{'ips'} }, $_;
       $conf{ lc($key) } = $val;        }
     }      } else {
   }        my ($key, $val) = split /\s+/, $_, 2;
   close $fh;  
         if (lc($key) eq 'ips') {
   #print Dump \%conf;          $in_ip_list = 1;
   foreach (          next;
     'password',        }
     'file_name', 'file_size', 'file_cksum',  
     'ver', 'cksum', 'ips',        $key =~ s/^\s+//;
   ) {        $key =~ s/\s+$//;
     die "No $_ specified in config file!"        $val =~ s/^\s+//;
       if (not exists $conf{$_});        $val =~ s/\s+$//;
   }  
         $conf{ lc($key) } = $val;
   #print Dump \%conf;      }
   #exit;    }
   return \%conf;    close $fh;
 }  
     #print Dump \%conf;
 package Trango::Telnet;    foreach (
 use base 'Net::Telnet';      'password',
       'file_name', 'file_size', 'file_cksum',
 my %PRIVATE = (      'ver', 'cksum', 'ips',
   connected => 0,    ) {
   logged_in => 0,      die "No $_ specified in config file!"
 );        if (not exists $conf{$_});
     }
 sub new {  
   my $class = shift;    #print Dump \%conf;
   my $args = shift || {};    #exit;
     return \%conf;
   $args->{'Timeout'} ||= 5;  }
   $args->{'Prompt'}  ||= '/#> *$/';  
   package Mylogger;
   foreach my $key (keys %{ $args }) {  
     $PRIVATE{$key} = $args->{$key};  use Fcntl ':flock'; # import LOCK_* constants
   }  #use YAML;
   use constant LOG_PRINT => 128;
   my $self = $class->SUPER::new(%{ $args });  use constant LOG_SAVE  =>  64;
   bless $self;  
   DESTROY {
   #bless $self, $package;    my $self = shift;
   return $self;    if ($self->{'MYLOG'}) {
 }      $self->p("Closing log ($self->{'log_path'}/$self->{'log_file'})");
       close $self->{'MYLOG'};
 sub connect    }
 {  }
   my $self = shift;  
   sub new {
   unless ( $self->open(    my $package = shift;
       Host => $PRIVATE{'Host'},    my $self = shift || {};
       Errmode => 'return',  
   ) ) {    $self->{'base_path'}  ||= '.';
     $! = "Couldn't connect to $self->{'Host'}.  Connection timed out.";    $self->{'log_path'}   ||= $self->{'base_path'};
     return undef, undef;    $self->{'log_prefix'} ||= 'LOG';
   }    $self->{'log_file'}   ||= GetLogName(
   #$self->dump_log('dump.log');      $self->{'log_prefix'},
       $self->{'log_path'}
   ## Login to remote host.    );
   unless ($self->waitfor(    bless $self, $package;
     -match => '/password: ?$/i',  }
     -errmode => "return",  
   ) ) {  sub s
     $! = "problem connecting to host ($self->{'Host'}): " . $self->lastline;  {
     return undef;    my $self = shift;
   }    my $m = shift;
     return $self->mylog($m, LOG_SAVE);
   $self->login_banner($self->lastline);  }
   
   $PRIVATE{'connected'} = 1;  sub p
   {
   return ($self->host_type, $self->firmware_version);    my $self = shift;
 }    my $m = shift;
     return $self->mylog($m, LOG_PRINT);
 sub login  }
 {  
   my $self = shift;  sub sp
   {
   my $password = shift;    my $self = shift;
     my $m = shift;
   $self->print($password);    return $self->mylog($m, LOG_SAVE | LOG_PRINT);
   unless ($self->waitfor(  }
     -match => $self->prompt,  
     -errmode => "return",  sub mylog
   ) ) {  {
     $! = "login ($self->{'Host'}) failed: " . $self->lastline;    my $self = shift;
     return undef;  
   }    my $thing = shift;
     chomp $thing;
   $PRIVATE{'logged_in'} = 1;  
     my $which = shift;
   return 1;  
 }    my $MYLOG;
     if ($which & LOG_PRINT) {
 sub login_banner      print $thing, "\n";
 {    }
   my $self = shift;  
     if ($which & LOG_SAVE) {
   my $banner = shift || $PRIVATE{'login_banner'};      if ($self->{'MYLOG'}) {
         $MYLOG = $self->{'MYLOG'};
   my ($type, $ver) = $banner =~      } else {
     /Welcome to Trango Broadband Wireless (.+)[\s-](\w+)$/i;        unless ($MYLOG) {
                   open ($MYLOG, '>>', $self->{'log_path'} . '/' . $self->{'log_file'})
   $self->host_type($type);            or die "Couldn't open logfile!\n";
   $self->firmware_version($ver);          my $ofh = select $MYLOG;
           $|=1;
   return $banner;          select $ofh;
 }          $self->{'MYLOG'} = $MYLOG;
   
 sub host_type          $self->p("Opened log ($self->{'log_path'}/$self->{'log_file'})");
 {        }
   my $self = shift;      }
       flock($MYLOG, LOCK_EX);
   my $type = shift || $PRIVATE{'host_type'};      print $MYLOG (scalar gmtime), "\t", $thing, "\n"
   $PRIVATE{'host_type'} = $type;        or die "Couldn't print to MYLOG: $!";
       flock($MYLOG, LOCK_UN);
   return $type;    }
 }  }
   
 sub firmware_version  sub GetLogName
 {  {
   my $self = shift;    my $prefix  = shift || die "Invalid prefix passed for log";
   
   my $ver = shift || $PRIVATE{'firmware_version'};    my $logdate = GetLogDate();
   $PRIVATE{'firmware_version'} = $ver;    my $logver  = 0;
       my $logname;
   return $ver  
 }    do {
       $logname = $prefix . $logdate . sprintf("%02d", $logver) . '.log';
 sub Host      $logver++;
 {    } until (not -e $logname);
   my $self = shift;  
       return $logname;
   my $host = shift || $PRIVATE{'Host'};  }
   $PRIVATE{'HOST'} = $host;  
   sub GetLogDate
   return $host;  {
 }    my ($sec,$min,$hour,$mday,$mon,$year,,,) = localtime();
   
     $mon++;
 sub reboot    $year += 1900;
 {  
   my $self = shift;    if ($min  < 10) { $min  = "0$min"  }
     if ($sec  < 10) { $sec  = "0$sec"  }
   $self->print("reboot\n");    if ($hour < 10) { $hour = "0$hour" }
   $self->getline;    if ($mday < 10) { $mday = "0$mday" }
     if ($mon  < 10) { $mon  = "0$mon"  }
   return 1;  
 }    my $time = $year . $mon . $mday;
   
 sub exit    return $time;
 {  }
   my $self = shift;  
   
   $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.16

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