and a file hosts.dat containing the the host names#!/usr/bin/perl while (<STDIN>) { chomp; open(H, "ssh $_ 'uptime' 2>&1 |"); $b = <H>; close(H); printf("%s: %s\n", $_, $b); }
and assuming appropriate ssh keys in place and passphases entered, I'd expect the output oflarry curley moe
to be something along the line of./test.pl <hosts
Instead, I get only the first line before the program exits. Commenting out these two lines:larry: 22:20:46 up 53 days, 1:27, 1 user, load average: 0.06, 0.04 +, 0.05 curley: 22:20:46 up 67 days, 7:56, 1 user, load average: 0.07, 0.0 +5, 0.05 moe: 22:20:47 up 12 days, 11:22, 1 user, load average: 0.04, 0.04, + 0.05
allows the script to hit all three hosts, but without the requested uptime info. Uncommenting either line reverts to single line output. Also prefixing the ssh command with 'echo' correctly echos the command for all three hosts.$b = <H>; close(H);
Based on my tinkering it would appear that reading any input from the ssh command or closing it's filehandle is somehow clobbering perl's STDIN stream. I can think of a number of possible ways around this situation, but I'm curious about why it's happening in the first place.
In reply to Odd perl/ssh interaction by mlf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |