1

When I execute this from command line, I get prompted for joe's password (which is what I want):

ssh -t 192.168.1.32 'scp joe@192.168.1.31:/etc/hosts /tmp'

When I try to run the same command from a perl script, it just hangs there (with no prompt):

`ssh -t 192.168.1.32 'scp joe\@192.168.1.31:/etc/hosts /tmp'`;

How can I make this work from a Perl script?

Note: No, I cannot use key-based authentication for this.

2

You could use Perl's Net::SCP for this, which would be the cleanest (all-perl, no external command calls) solution.

Or you could do as Andrew suggests and use Expect (which is probably quicker).

Or you could fork(), exec(), and waitpid() (letting your scp command have the terminal your Perl script is running from so it can get passwords from you, which is a nice old-school Unix-y approach, but way more work than I'd be willing to do personally).

TIMTOWTDI. :-)

0

I had the exact same kind of issues some time ago.

The reason it hangs is because ssh spawns a terminal for the password input. Perl can can not catch this terminal (for reason). "Password" string is never seen by perl.

It's better to use the libs ( Net::SSH2 libs or something similar).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.