I am trying to gain access of remote server from perl script using ssh command and then I need to call other script file.I am using here ssh public-private key authentication to gain access with out asking any password of remote server.By executing this script i am getting this error:
Name or service not known
Here is my code:
There are some issues in your code.
use warnings;in your scripts.
Perl tries to interpolate the
i.e. it will try to somehow evaluate an array called
(which doesn't exist).
use strict; and
use warnings; would have told you that:
Possible unintended interpolation of @1 in string at... ssh: Could not resolve hostname root.2.3.4: Name or service not known.
From this you could have seen that actually the command
was issued (because Perl interpolated the
@1 away) which makes no sense.
You have to either escape the
@ (by prepending a backslash,
or use single quotes
' instead of double quotes
" so that Perl
doesn't interpolate that
system()calls because they are executed completely unrelated to each other. The 1st one does (well, does not) an ssh to the remote machine and gets stuck there. The 2nd call tries to execute
/root/abc.plafter the 1st call has finished, i.e. it does so on your local machine. The 3rd calls simply locally executes
exitin a subshell which basically does nothing.
Putting this together we get
#!/usr/bin/env perl use strict; use warnings; system('ssh firstname.lastname@example.org /root/abc.pl');
This will ssh to 126.96.36.199 and execute the script
/root/abc.pl there (in one go) and return after the script has finished.