Reputation: 509
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
Upvotes: 0
Views: 881
Reputation: 10234
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');
Upvotes: 0
Reputation: 47829
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 );
Upvotes: 1