I have 2 of these loops to make sure that there are entries in the /etc/hosts file, but they don't run!? any ideas?
##Get the sub host names, the top level host is also used, this makes the single machine version work, too.
my $stmt = "SELECT hostname FROM $mysqldbname.host";
my $sth = $sqlhandle->prepare($stmt);
push (@err, "Error 202 in import.pl, can't prepare $stmt\n" if $DBI::err;
$sth->execute;
push (@err, "Error 203 in import.pl, can't execute $stmt\n" if $DBI::err;
my @sub_hosts;
@sub_hosts = $sth->fetchrow_array();
push(@sub_hosts, $informix_host);
##Get the corresponding array for ip's.
my $stmt = "SELECT ip_addr FROM $mysqldbname.host";
my $sth = $sqlhandle->prepare($stmt);
push (@err, "Error 203.2 in import.pl, can't prepare $stmt\n" if $DBI::err;
$sth->execute;
push (@err, "Error 203.4 in import.pl, can't exec $stmt\n" if $DBI::err;
my @sub_hosts_ip;
@sub_hosts_ip = $sth->fetchrow_array();
#print @sub_hosts;
###########################################################################################
#Make sure each sub_host is in the /opt/informix/etc/sqlhosts, and /etc/hosts
#as well, we may need to add them.
###########################################################################################
open (OLD, "< /opt/informix/etc/sqlhosts"
open (NEW, "> /opt/informix/etc/oldhosts"
$flag = 1;
select(NEW);
foreach $hst (@sub_hosts){
print "HOST $hst";
while((<OLD>) && ($flag == 1)){
@a = split(/#/,$_);
print STDOUT $a[0];
if(/$hst/, $a[0]){
$flag = 0;
print NEW $_;
}else{
print NEW $_;
}
}
if($flag == 0){
#append new entry
@these = split(/./,$hst);
print NEW "ol_$these[0] sesoctcp $hst sqlexec";
$flag = 1;
}}
close(OLD);
close(NEW);
rename("/opt/informix/etc/sqlhosts", "/opt/informix/etc/prevhosts"
rename("/opt/informix/etc/oldhosts", "/opt/informix/etc/sqlhosts"
#######################################################################################
#Done adding to /opt/informix/etc/sqlhosts->add to /etc/hosts now!
######################################################################################
##Get the sub host names, the top level host is also used, this makes the single machine version work, too.
my $stmt = "SELECT hostname FROM $mysqldbname.host";
my $sth = $sqlhandle->prepare($stmt);
push (@err, "Error 202 in import.pl, can't prepare $stmt\n" if $DBI::err;
$sth->execute;
push (@err, "Error 203 in import.pl, can't execute $stmt\n" if $DBI::err;
my @sub_hosts;
@sub_hosts = $sth->fetchrow_array();
push(@sub_hosts, $informix_host);
##Get the corresponding array for ip's.
my $stmt = "SELECT ip_addr FROM $mysqldbname.host";
my $sth = $sqlhandle->prepare($stmt);
push (@err, "Error 203.2 in import.pl, can't prepare $stmt\n" if $DBI::err;
$sth->execute;
push (@err, "Error 203.4 in import.pl, can't exec $stmt\n" if $DBI::err;
my @sub_hosts_ip;
@sub_hosts_ip = $sth->fetchrow_array();
#print @sub_hosts;
###########################################################################################
#Make sure each sub_host is in the /opt/informix/etc/sqlhosts, and /etc/hosts
#as well, we may need to add them.
###########################################################################################
open (OLD, "< /opt/informix/etc/sqlhosts"
open (NEW, "> /opt/informix/etc/oldhosts"
$flag = 1;
select(NEW);
foreach $hst (@sub_hosts){
print "HOST $hst";
while((<OLD>) && ($flag == 1)){
@a = split(/#/,$_);
print STDOUT $a[0];
if(/$hst/, $a[0]){
$flag = 0;
print NEW $_;
}else{
print NEW $_;
}
}
if($flag == 0){
#append new entry
@these = split(/./,$hst);
print NEW "ol_$these[0] sesoctcp $hst sqlexec";
$flag = 1;
}}
close(OLD);
close(NEW);
rename("/opt/informix/etc/sqlhosts", "/opt/informix/etc/prevhosts"
rename("/opt/informix/etc/oldhosts", "/opt/informix/etc/sqlhosts"
#######################################################################################
#Done adding to /opt/informix/etc/sqlhosts->add to /etc/hosts now!
######################################################################################