cmv has asked for the wisdom of the Perl Monks concerning the following question:
I have the need to tail a bunch of files on remote machines, all at the same time, and print the intermixed lines as they come in (ala xtail). My hands are tied, in that I can't use any perl modules that are not already installed on the existing machine.
Luckily, the current machine has IO::Select, so my current plan is to open file descriptors that are reading the output pipe from the ssh commands, and use select to tell me when there is input on any of them.
I can get this select strategy to work with commands run on the local machine, but anytime I try to ssh that exact same command to a remote machine, I get the following error:
tcsetattr: I/O error
and the ssh connection closes. Attached is my current test script. Any help is very much appreciated!
Thanks
-Craig
use strict; use warnings; use IO::Select; my $cmd1 = "cat /etc/passwd"; my $sshcmd = "/usr/bin/ssh -t -i \$HOME/.ssh/mypubkey -o 'StrictHostKe +yChecking no' user\@host $cmd1"; # Prove command works... my $out = `$sshcmd`; print STDERR "OUT:\n$out"; #open(IFILE, "$cmd1 |") || die "Bad open"; # This will work open(IFILE, "$sshcmd |") || die "Bad open"; # This does not my $select = IO::Select->new(); $select->add(\*IFILE); my @ready; while ( @ready = $select->can_read(5) ) { foreach my $fh (@ready) { my $line = <$fh>; STDERR "line=$line"; if(eof($fh)) { $select->remove($fh); close($fh) || warn "Close problem on fh: $fh"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IO::Select & ssh problem
by ikegami (Patriarch) on Sep 17, 2009 at 17:44 UTC | |
by cmv (Chaplain) on Sep 18, 2009 at 18:52 UTC | |
|
Some Progress, but still NEED HELP!
by cmv (Chaplain) on Sep 21, 2009 at 14:44 UTC | |
|
Solution: Don't know why it works...
by cmv (Chaplain) on Sep 21, 2009 at 18:42 UTC | |
by ikegami (Patriarch) on Sep 21, 2009 at 18:47 UTC | |
by cmv (Chaplain) on Sep 22, 2009 at 12:47 UTC | |
|
Re: IO::Select & ssh problem
by cmv (Chaplain) on Sep 22, 2009 at 20:18 UTC |