my goal is to connect in SSH to several material and without the result in STDOUT, pass in console some command.

It is even more simple than what you tried. Sample transcript:

qwurx [shmem] ~> perl -e 'open my $fh,"|-","ssh localhost"; while(<STD +IN>){print $fh $_}' Pseudo-terminal will not be allocated because stdin is not a terminal. The programs included with the Debian GNU/Linux system are free softwa +re; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. You have new mail. touch blorflydick <--- input at terminal touch gobbledygook <--- input at terminal ^D <--- input at terminal (Ctrl-D or eof) qwurx [shmem] ~> ls -lrt | tail -2 <--- after perl terminated -rw-r--r-- 1 shmem shmem 0 Mar 15 18:30 blorflydick -rw-r--r-- 1 shmem shmem 0 Mar 15 18:30 gobbledygook

No modules required. If you just want to pass some commands and don't care about STDOUT/STDERR, all you have to do is a plain piped open. If you want to multiplex the commands to several hosts, store the filehandles in an array and print your input to the remote shells in a loop (untested):

my @fh; for my $ip (@ips) { open my $fh,"|-","ssh $ip" or die "Can't ssh to $ip: $!\n"; push @fh, $fh; } while (<STDIN>) { for my $fh (@fh) { print $fh $_; } }

You might, since you are not interested in STDOUT/STDERR, redirect all output within the piped open to avoid funny blocking errors and/or spamming your terminal:

open my $fh,"|-","ssh $ip >/dev/null 2>&1" or die "Can't ssh to $i +p: $!\n";

and/or set $|=1 (see perlvar) and/or call $fh->autoflush on every handle created. Finding out the difference between these measures is left as an excercise to the reader.

update: the ssh connection in this example was established using ssh keys and a running ssh-agent. If you have to enter (different) credentials you want to set $fh->autoflush and use sshpass to pass the passwords (for each connection).

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

In reply to Re: SSH and expect without module by shmem
in thread SSH and expect without module by touriste75

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.