msomanat has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a perl script which connects to a remote linux box from my Windows, executes a perl script there, and copies the result file to my windows machine. The code looks like:

$server = "x.x.x.x"; my $putty = "C:\\Users\\xxxxxxx\\Downloads\\putty"; my $location = "C:\\Users\\xxxxxxx\\Documents"; open(my $pipe, "$putty\\plink -pw <password> root\@$server /usr/bin/pe +rl /manu/test/test.pl |") or die "unable to run command: $!"; print "Success"; open(my $pipe1, "$putty\\pscp -pw <password> root\@$server:/manu/test/ +logcollected $location |") or die "unable to run command: $!"; print "\n Again success";

This script works fine for me. But I have a hard coded value in the remote script, for which I need to dynamically pass a value from my windows machine. Please help me to know if there is any way for achieving it?

Replies are listed 'Best First'.
Re: Pass a parameter to remote perl script
by aitap (Curate) on Aug 04, 2012 at 09:19 UTC

    Command line parameters can be passed right after executable file name, according to the documentation:

    Usage: plink [options] [user@]host [command]
    Run your commands like this: system("$putty\\plink -pw <password> root\@$server /usr/bin/perl /manu/test/test.pl $myparameter")

    Inside the remote script, use @ARGV or Getopt::Std or Getopt::Long.

    You can also write your script using Net::SSH, not PuTTY. Authorisation by public key is also safer when running a script.

    Sorry if my advice was wrong.
Re: Pass a parameter to remote perl script
by Anonymous Monk on Aug 04, 2012 at 08:44 UTC