I'm new to programming. I have written a perl script which does the following. 1) ssh into a remote machine 2) execute a sequence of commands. The script requires user interaction in between.It needs user name and password. I'm not sure how to proceed with that.

use Net::SSH::Expect; use strict; use warnings; #login to a remote host my $ssh = Net::SSH::Expect->new (host => "ipaddr", password=> 'pwd', user => 'username', raw_pty => 1); my $login_output = $ssh->login();

The login is successful. Now, for the below scp command i'm prompted to enter the username and password of that system. Enter usename for remote scp server: Enter the password for the remote server: The script stops here. This is what i tried.but no luck

my $cpscp = $ssh->exec("copy scp install ip addr filename"); my $usr = $ssh->waitfor ("Enter usename for remote scp server:\s*\z ", + 5); if ($usr) { print("string found \n"); my $pwd =$ssh->send("root"); } else { print("No string found\n"); }

The script is unable to identify it. "no string found" I also tried the following

$ssh->waitfor('Enter username for remote scp server:\s*\z ', 5) or die + "not found"; $ssh->send("root");

In reply to perl : $ssh->waitfor by user786

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.