Filehandle that reads remsh output
Quote:
>I have a Perl script I'm playing with that tries to use a filehandle
>to read output from a remsh command:
>#!/usr/bin/perl
>$| = 1;
>open(MACHINES,"my_primary_machines");
> while($mach = <MACHINES>) {
> open(BDF,"remsh $mach bdf |");
> print "Looking at machine $mach\n";
> while($line = <BDF>) {
> print $line;
> }
> }
>I expected that to remsh to the machine, execute the command,
>and then print each line ouf output. What it actually does is
>remsh to the machine and sit there till I manually "exit" them
>remsh, and THEN it does the bdf and closes...any ideas?
You forgot to remove the newline from $mach. Consequently you're
running two-line scripts, as in
open(BDF, "remsh your_first_machine
bdf |");
In the shell, that's two commands. First it runs remsh without
arguments (which runs rlogin). After you logout from the remote
machine, bdf is run on your local machine.
By the way, remsh does unspeakable things to your keyboard.
If you're remsh'ing a command that doesn't take input, use
remsh's -n option.
If you don't close BDF, there'll be a zombie process until your
script terminates.
#!/usr/bin/perl
$| = 1;
open(MACHINES,"my_primary_machines");
while($mach = <MACHINES>) {
chop $mach;
open(BDF,"remsh -n $mach bdf |");
print "Looking at machine $mach\n";
while($line = <BDF>) {
print $line;
}
close BDF; # don't leave a zombie
}
--
Hope this helps,
HansM