I've got a perl script that automatically logs me via ssh by spawning ssh with Expect.pm. It actually works pretty well and here is my ouput :
$ ngh bestServerEver GPG Pass : root@**********'s password: Linux **** 2.6.32-042stab059.7 #1 SMP Tue Jul 24 19:12:01 MSK 2012 x86 +_64 GNU/Linux motd!!!!!!!!!! Last login: Mon Feb 4 22:18:10 2013 from ******************* bash [root@******:~]$ bash [root@******:~]$
I'm trying to suppress this output to get to the server shell directly after typing my command. Like that :
$ngh BestServerEver root@server#
I've tried that answer :

http://stackoverflow.com/questions/1376607/how-can-i-suppress-stdout-temporarily-in-a-perl-program

I've also tried :
local (*OUT, *ERR); open OUT, ">&STDOUT"; open ERR, ">&STDERR"; close STDOUT; close STDERR; print "don't print"; open STDOUT, ">&OUT"; open STDERR, ">&ERR";
Both are okay when it's about standard STDOUT but Expect seems to be a different kind of handle or whatever. I've also tried setting :
$exp->stty("-echo");
But it did not hide anything Finally, here is the sub that spawns ssh

http://pastebin.com/pSL3AwBW <-- with color!

if you have some tips to give me on how to hide that junk :p
sub interactiveSsh { my ($pConfig,$pass)=@_; my $exp = new Expect; $exp->slave->clone_winsize_from(\*STDIN); $exp->spawn("ssh root\@".$pConfig->{'host'}); my $spawn_ok; $exp->expect(40, [ qr'(yes/no)', sub { my $fh = shift; $fh->send("yes\n"); exp_continue; } ], [ qr'assword:', sub { if ($spawn_ok) { $exp->interact(); } my $fh = shift; $fh->send("$pass\n"); $spawn_ok=1; exp_continue; } ], [ qr'#', sub { my $fh = shift; $fh->send("bash\n"); $exp->send("stty -echo\n"); $exp->interact(); exp_continue; } ], [ eof => sub { if ($spawn_ok) { print BOLD GREEN, "SSH + close connexion to ".$pConfig->{'host'}.".\n", RESET; exit 0; } else { die "ERROR: could not +spawn ssh.\n"; } } ], [ timeout => sub { die "No login.\n"; } ], '-re', qr'[#>:] $', ); $exp->interact();

In reply to hiding Expect output by AzryelRyvel

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.