0

I was trying to perform password less login using ssh in perl. I am somehow stuck up with the following error message:

ssh: Could not resolve hostname : Name or service not known
lost connection

The following was a part of my code in the perl script that threw up this error:

$dut_ip_addr="10.0.0.110";
system("scp run_application.sh isq\@\$dut_ip_addr\:\/home\/isq\/");

Any help would be greatly appreciated

2 Answers 2

1

Here is your problem:

\$dut_ip_addr

Why are you escaping the dollar sign? That way, Perl will not interpolate that variable for you and scp will try to connect to $dut_ip_addr which will of course fail.

There are a couple more backslashes in your code that don't make much sense. I suggest, you do something like this:

$dut_ip_addr = "10.0.0.110";
my $login    = "isq";
my $path     = "/home/isq/";
my $scp_command = sprintf 'scp run_application.sh %s@%s:%s', $login, $dut_ip_addr, $path;
system( $scp_command );
Sign up to request clarification or add additional context in comments.

Comments

0

You can use Net::OpenSSH and forget about all the bothersome quoting details:

use Net::OpenSSH;

my $ssh = Net::OpenSSH->new($dut_ip_addr, user => 'isq');
$ssh->scp_put('run_application.sh', '/home/isq/run_application.sh');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.