version 1.5, 2005/11/16 21:39:51 |
version 1.8, 2005/11/17 20:20:59 |
|
|
#!/usr/bin/perl
|
#!/usr/bin/perl
|
# $RedRiver: update_trango.pl,v 1.4 2005/11/16 21:13:39 andrew Exp $
|
# $RedRiver: update_trango.pl,v 1.7 2005/11/17 20:09:45 andrew Exp $
|
########################################################################
|
########################################################################
|
# update_trango.pl *** Updates trango foxes with a new firmware
|
# update_trango.pl *** Updates trango foxes with a new firmware
|
#
|
#
|
|
|
use Net::TFTP;
|
use Net::TFTP;
|
use Fcntl ':flock'; # import LOCK_* constants
|
use Fcntl ':flock'; # import LOCK_* constants
|
#use YAML;
|
#use YAML;
|
|
use constant LOG_SAVE => 1;
|
|
|
|
|
my $config_file = shift || 'update_trango.conf';
|
my $config_file = shift || 'update_trango.conf';
|
my $conf = read_conf($config_file);
|
|
|
|
my $max_tries = 1;
|
my $max_tries = 1;
|
|
|
my $log_file = GetLogName('UT');
|
|
use constant LOG_SAVE => 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $log_file = GetLogName('UT');
|
my $MYLOG; # file handle for logging so we don't have to close and open it all the time
|
my $MYLOG; # file handle for logging so we don't have to close and open it all the time
|
END {
|
END {
|
if ($MYLOG) {
|
if ($MYLOG) {
|
|
|
}
|
}
|
|
|
|
|
|
mylog("Reading config file '$config_file'", LOG_SAVE);
|
|
my $conf = read_conf($config_file);
|
|
|
|
mylog(" Hardware Type: $conf->{'type'}", LOG_SAVE);
|
|
mylog(" File Name: $conf->{'file_name'}", LOG_SAVE);
|
|
mylog(" File Size: $conf->{'file_size'}", LOG_SAVE);
|
|
mylog(" File Checksum: $conf->{'file_cksum'}", LOG_SAVE);
|
|
mylog(" FW Version: $conf->{'ver'}", LOG_SAVE);
|
|
mylog(" FW Checksum: $conf->{'cksum'}", LOG_SAVE);
|
|
mylog("", LOG_SAVE);
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach my $fox (@{ $conf->{'ips'} }) {
|
foreach my $fox (@{ $conf->{'ips'} }) {
|
mylog("Updating: $fox", LOG_SAVE);
|
mylog("Updating: $fox", LOG_SAVE);
|
|
|
|
|
my $host = new Net::Telnet (Timeout => 5,
|
my $host = new Net::Telnet (Timeout => 5,
|
Prompt => '/#> *$/');
|
Prompt => '/#> *$/');
|
mylog("Connecting to $fox");
|
mylog("Connecting to $fox");
|
$host->open($fox);
|
unless ( $host->open( Host => $fox, Errmode => 'return') ) {
|
|
mylog("Couldn't connect to $fox. Connection timed out.", LOG_SAVE);
|
|
next;
|
|
}
|
$host->dump_log('dump.log');
|
$host->dump_log('dump.log');
|
|
|
## Login to remote host.
|
## Login to remote host.
|
$host->waitfor(
|
unless ($host->waitfor(
|
-match => '/password: ?$/i',
|
-match => '/password: ?$/i',
|
-errmode => "return",
|
-errmode => "return",
|
) or die "problem connecting to host ($fox): ", $host->lastline;
|
) ) {
|
|
mylog("problem connecting to host ($fox): " . $host->lastline, LOG_SAVE);
|
|
next;
|
|
}
|
|
|
my $login_banner = $host->lastline;
|
my $login_banner = $host->lastline;
|
my ($type, $version) = $login_banner =~
|
my ($type, $version) = $login_banner =~
|
|
|
next if /^#/;
|
next if /^#/;
|
next if /^$/;
|
next if /^$/;
|
if ($in_ip_list) {
|
if ($in_ip_list) {
|
push @{ $conf{'ips'} }, $_;
|
if (/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)(\d{1,3})-(\d{1,3})/) {
|
|
push @{ $conf{'ips'} }, $1 . $_ for ($2..$3);
|
|
} else {
|
|
push @{ $conf{'ips'} }, $_;
|
|
}
|
} else {
|
} else {
|
my ($key, $val) = split /\s+/, $_, 2;
|
my ($key, $val) = split /\s+/, $_, 2;
|
|
|
|
|
if (not exists $conf{$_});
|
if (not exists $conf{$_});
|
}
|
}
|
|
|
|
#print Dump \%conf;
|
|
#exit;
|
return \%conf;
|
return \%conf;
|
}
|
}
|
|
|