0

I am using the following command in a perl script to run a shell script with input parameter that resides in a particular folder of a different server.

system('sshpass -p password ssh user@hostname "cd /folder1/fol2; ./test.sh $param1 $param2;"');

But it seems that the input parameter is not getting considered. Can anyone help on this please?

2
  • 3
    Variables do not interpolate within single quotes. Commented Apr 4, 2017 at 22:06
  • Thanks mate! I have finally used another shell script to do the ssh and called the same from my perl with system command and that worked! Commented Apr 5, 2017 at 8:51

1 Answer 1

2

Quoting by hand is tricky, let perl do it for you:

use Net::OpenSSH;
my $ssh = Net::OpenSSH->new('user@hostname', password => $password);
$ssh->system('cd', '/forlder1/fol2', \\'&&', './test.sh', $param1, $param2)
    or $ssh->die_on_error("Command failed");
Sign up to request clarification or add additional context in comments.

1 Comment

I don't have privilege to install the package. But finally able to achieve the same by calling another shell script.

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.