Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gmmastros on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with foreach problem...

Status
Not open for further replies.

mbaranski

Programmer
Nov 3, 2000
421
0
0
US
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, &quot;< /opt/informix/etc/sqlhosts&quot;);
open (NEW, &quot;> /opt/informix/etc/oldhosts&quot;);
$flag = 1;
select(NEW);

foreach $hst (@sub_hosts){
print &quot;HOST $hst&quot;;
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 &quot;ol_$these[0] sesoctcp $hst sqlexec&quot;;
$flag = 1;
}}

close(OLD);
close(NEW);
rename(&quot;/opt/informix/etc/sqlhosts&quot;, &quot;/opt/informix/etc/prevhosts&quot;);
rename(&quot;/opt/informix/etc/oldhosts&quot;, &quot;/opt/informix/etc/sqlhosts&quot;);
#######################################################################################
#Done adding to /opt/informix/etc/sqlhosts->add to /etc/hosts now!
######################################################################################
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top