Thanks to Mike Wei for the nugget that eventually turned into the
answer. I've got two perl scripts below.
============================================================
First, here is the perl code to build a complete hash
of all the robots and their various control hosts
============================================================
#!/usr/local/bin/perl
open(VMQUERY, "vmquery -a |");
while ($line = <VMQUERY>) {
next unless ( $line =~ /robot number|robot host/ ) ;
chomp $line ;
@tmp = split /\s+/, $line;
if ( $line =~ /robot number/ ) { $robot_num = $tmp[2]} ;
if ( $line =~ /robot host/ ) {
$robot_host = $tmp[2] ;
$robot_control_host{$robot_num} = $robot_host ;
} ;
}
foreach $robot_num (keys %robot_control_host) {
print "$robot_num\t$robot_control_host{$robot_num}\n";
}
===========================================================
With a slight modification, here is the perl code to get
the robot control host for robot 0:
===========================================================
#!/usr/local/bin/perl
$robot=0 ;
open(VMQUERY, "vmquery -a |");
while ($line = <VMQUERY>) {
next unless ( $line =~ /robot number|robot host/ ) ;
chomp $line ;
@tmp = split /\s+/, $line;
if ( $line =~ /robot number/ ) { $robot_num = $tmp[2]} ;
if ( $line =~ /robot host/ ) {
$robot_host = $tmp[2] ;
$robot_control_host{$robot_num} = $robot_host ;
#This next line is really the only difference. If the robot number
#of this robot matches the one we're looking for, we can quit now.
#This will speed things up a bit.
if ( $robot_num == $robot ) { last };
} ;
}
$control_host = $robot_control_host{$robot} ;
|