Hello monks of Perl Knowledge
I am having an odd problem with SSH connection using Expect module.
As part of an application, I need to execute a command on the remote host via ssh. As it requires a pseduo-tty, I addedd '-t -t' flag to ssh
to force it to allocate a pseduo-tty. Without this flag I am getting warning message "Pseduo-terminal will not be allocated because stdin is not a terminal"
The warning/error in question is "tcgetattr: No such device or address". I get this error while passing the password to remote host.
Code snippet below,
use Expect;
my $ssh = new Expect();
$ssh->spawn( "ssh user\@172.23.1.1" );
$ssh->expect(10, "password:");
print $ssh "$passwd\r";
$ssh->expect(65, "\$" );
print $ssh "$cmd\r";
$ssh->expect(65, "\$" );
my $output = $ssh->exp_before();
$ssh->soft_close() ;
print "$output";
Can anyone help me out !
Thanks
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.