Heyy

I could make get it work and could switch to the user with the help of expect and here is the code

my $ssh = Net::SSH::Expect->new(host=>$ip, user=>$user, password=>$pass, raw_pty=>1 ) or die " Cannot O +pen "; $login_check=$ssh->login(); print "LOGIN for $ip -- $login_check \n"; my $who = $ssh->exec('who am i '); print "\n OUT1 $who \n"; my $ls = $ssh->exec('touch /tmp/YES_net '); print "\n OUT2 - $ls \n"; $ssh->exec("stty raw -echo"); $passwd = "sprintdream"; $tmp1 = $ssh->send("su root -c 'touch /tmp/YESIDIDIT' "); $tmp2 = $ssh->waitfor('Password:\s*\z', 3) or die "prompt 'pas +sword' not found after 1 second"; #$tmp3 = $ssh->send("su root -c whoami "); $tmp3 = $ssh->send("$passwd"); print " Output ==>1 $tmp1 2 $tmp2 3 $tmp3 \n"; #while ($chunk = $ssh->peek(1)) { # grabs chunks of output eac +h 1 second # #print $ssh->eat($chunk); # print " Chunk => $chunk \n"; #} while ( defined ($line = $ssh->read_line()) ) { print " Line => $line " . "\n"; }
Thanks & Regards
Sushil Kumar

In reply to Re: Using Expect module in Net::Telnet by msk_0984
in thread Using Expect module in Net::Telnet by msk_0984

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.