I'm using the stdout_fh option in the "spawn" function in Net::OpenSSH to write standard output to a file. The problem is, for some reason I'm having trouble later reading the contents of the file. When I try to open the file for reading, I get an error message, "mux_client_request_session: read from master failed: Broken pipe". Any ideas what this message means?
The output file contains the information I want, I'm just not able to read it in the same Perl script. I can make a new Perl script and read it just fine, however. If I print to the same file in the normal way first, I can read what I print, but not the contents of standard output below that line. If I first write standard output contents to the file, and then print to the file normally, I can't read what I print.
You can try to reproduce my problem by filling in 2 remote hosts you have access to and user name and password here. This script prints the standard output from the "hostname" command to "filename.txt". You can un-comment the "print testing" line to print to "filename.txt" and see if you can read it.
Thanks to anyone who can help me figure out what's wrong.
#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; my @hosts = ("host.name.1.edu", "host.name.2.edu"); my %conn = map { $_ => Net::OpenSSH->new(host => $_, user => 'user', port => 22, pa +ssword => 'password'); } @hosts; open (my $fh, ">filename.txt"); # print $fh "testing\n"; foreach(@hosts) { $conn{$_}->spawn({stdout_fh => $fh},'hostname'); } open(FILE1, "<filename.txt"); while(my $line1 = <FILE1>) { chomp $line1; print "$line1\n"; }
In reply to Net::OpenSSH stdout_fh problem by jbernest
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |