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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SSH with file handle

Status
Not open for further replies.

mrjazz

MIS
Apr 9, 2002
115
0
0
DE
The following seems to be pretty simple (but obviously not for me as I am not a Perl expert) ...
I want to collect the output from remote hosts and store it into a variable.
I must not use any CPAN modules in this environment.
What I have so far is the following:

Code:
open(my $ssh, "| ssh -T $onlineon");
print $ssh "/usr/sbin/vxassist -g $dg listtag  | $awk -F= '/activebase/ { print \$2 }'";
close($ssh) or die "$!";

I am connecting to the host which is stored in $onlineon and then want to store the output of the print line into another variable.
Problem: I am getting the right value back but cannot store it.

Thanks,
mrjazz
 
You're printing the data, but not storing it.
 
Try something like this
Perl:
open(my $ssh, "| ssh -T $onlineon >a_file 2>&1");
print $ssh "/usr/sbin/vxassist -g $dg listtag  | $awk -F= '/activebase/ { print \$2 }'";
close($ssh) or die "$!";
open(A_FILE,"a_file");
while(<A_FILE>){
  # process each line from the file, just print it in this example
  print $_; # $_ holds each line from the file in turn
}
close(A_FILE);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top