=================================================================== RCS file: /cvs/trango/Net-Telnet-Trango/scripts/update_trango.pl,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- trango/Net-Telnet-Trango/scripts/update_trango.pl 2005/11/16 21:13:39 1.4 +++ trango/Net-Telnet-Trango/scripts/update_trango.pl 2005/11/16 21:39:51 1.5 @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $RedRiver: update_trango.pl,v 1.3 2005/11/16 20:48:48 andrew Exp $ +# $RedRiver: update_trango.pl,v 1.4 2005/11/16 21:13:39 andrew Exp $ ######################################################################## # update_trango.pl *** Updates trango foxes with a new firmware # @@ -20,8 +20,8 @@ my $max_tries = 1; my $log_file = GetLogName('UT'); +use constant LOG_SAVE => 1; - my $MYLOG; # file handle for logging so we don't have to close and open it all the time END { if ($MYLOG) { @@ -38,7 +38,7 @@ foreach my $fox (@{ $conf->{'ips'} }) { - mylog("Updating: $fox"); + mylog("Updating: $fox", LOG_SAVE); ## Connect and login. my $host = new Net::Telnet (Timeout => 5, @@ -58,23 +58,26 @@ /Welcome to Trango Broadband Wireless (\w+)-(.+)$/i; if ($type ne $conf->{'type'}) { - mylog("Wrong type of unit ('$type' should be '$conf->{'type'}')"); + mylog("Wrong type of unit ('$type' should be '$conf->{'type'}')", LOG_SAVE); $host->close; next; } if ($version eq $conf->{'ver'}) { - mylog("Already up to date with firmware version '$version'"); + mylog("Already up to date with firmware version '$version'", LOG_SAVE); $host->close; next; } mylog("Logging in"); $host->print($conf->{'password'}); - $host->waitfor( + unless ($host->waitfor( -match => $host->prompt, -errmode => "return", - ) or die "login ($fox) failed: ", $host->lastline; + ) ) { + mylog("login ($fox) failed: " . $host->lastline); + next; + } mylog("Sending commands"); @@ -89,7 +92,7 @@ $host->getline; } $host->close; - mylog(""); + mylog("", LOG_SAVE); } sub upload @@ -105,7 +108,7 @@ $ver->{'Firmware Version'} eq $conf->{'ver'} && $ver->{'Firmware Checksum'} eq $conf->{'cksum'} ) { - mylog("Already updated!"); + mylog("Already updated!", LOG_SAVE); return 1; } @@ -122,7 +125,7 @@ mylog("Enabling TFTPd"); enable_tftpd($host) || die "Couldn't enable tftpd"; - mylog("Uploading file"); + mylog("Uploading file ($file)"); # use tftp to push the file up my $tftp = Net::TFTP->new($fox, Mode => 'octet'); @@ -135,25 +138,31 @@ #my @lines = $host->getlines; #print Dump \@lines; - mylog("Checking upload"); + mylog("Checking upload ($conf->{'file_cksum'})"); my $results = check_tftpd($host); # check the 'File Length' against ??? if ( $results->{'File Checksum'} ne $conf->{'file_cksum'}) { - mylog("File checksum does not match config file!"); + mylog("File checksum does not match config file!", LOG_SAVE); next; - } + } + mylog("File checksum ($results->{'File Checksum'}) " . + "matches ($conf->{'file_cksum'})"); if ($results->{'File Length'} !~ /^$conf->{'file_size'} bytes/) { - mylog("File length does not match config file!"); + mylog("File length does not match config file!", LOG_SAVE); next; } + mylog("File length ($results->{'File Length'}) " . + "matches ($conf->{'file_size'})"); if ( uc($results->{'File Name'}) ne uc($conf->{'file_name'}) ) { - mylog("File name does not match config file!"); + mylog("File name does not match config file!", LOG_SAVE); next; } + mylog("File name ($results->{'File Name'}) " . + "matches ($conf->{'file_name'})"); - mylog("Updating flash"); + mylog("Updating flash (new checksum '$conf->{'cksum'}')"); $results = updateflash( $host, $ver->{'Firmware Checksum'}, $conf->{'cksum'} ) or die "Couldn't update flash: " . $host->lastline; @@ -161,11 +170,13 @@ defined $results->{'Checksum'} && $results->{'Checksum'} eq $conf->{'cksum'} ) { - mylog("Saved checksum does not match config file!"); + mylog("Saved checksum does not match config file!", LOG_SAVE); next; } + mylog("Uploaded checksum ($results->{'Checksum'}) " . + "matches ($conf->{'cksum'})"); - mylog("Successfully updated!"); + mylog("Successfully updated!", LOG_SAVE); return 1; } } @@ -345,23 +356,27 @@ sub mylog { - my $thing = shift; - chomp $thing; + my $thing = shift; + chomp $thing; + my $save = shift; - unless ($MYLOG) { - open ($MYLOG, '>>', $log_file) - or die "Couldn't open logfile!\n"; - my $ofh = select $MYLOG; - $|=1; - select $ofh; - mylog("Opened log ($log_file)"); - } + print $thing, "\n"; - print $thing, "\n"; - flock($MYLOG, LOCK_EX); - print $MYLOG (scalar gmtime), "\t", $thing, "\n" - or die "Couldn't print to MYLOG: $!"; - flock($MYLOG, LOCK_UN); + if (defined $save && $save == LOG_SAVE) { + unless ($MYLOG) { + open ($MYLOG, '>>', $log_file) + or die "Couldn't open logfile!\n"; + my $ofh = select $MYLOG; + $|=1; + select $ofh; + mylog("Opened log ($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