Wise Monks-

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"; } } }

In reply to IO::Select & ssh problem by cmv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.