4

Is it possible to execute (from windows) a local script with arguments on a remote linux system?

Here's what I got:

plink 1.2.3.4 -l root -pw mypassword -m hello.sh

Is there a way to do this same thing, but able to give input parameters to hello.sh?

I've tried many things, including:

plink 1.2.3.4 -l root -pw mypassword -m hello.sh input1 input2

In this case it seems that plink thinks that input1 and input2 are its arguments.. which makes sense.

What are my options?

c_maker
  • 141

3 Answers3

1

I had the same issue.

You can simply write this line

plink 1.2.3.4 -l root -pw pass " myscript.sh arg1 arg2"

For example, I had to run a script and give two files as parameters.

plink 1.2.3.4 -l root -pw pass " myscript.sh path/to/file1 path/to/file2"

Hari
  • 111
0

For a more detailed description (for ssh) see this answer.

C:>type script.sh
#!/bin/bash
cd /home/user
echo "hello ${1:-}" > hello.txt

C:>plink user@host -pw password "bash -s" < script.sh "world"

C:>plink user@host -pw password "cat /home/user/hello.txt"
hello world
0

plink does not run the script as a sh script; it just sends its contents as separate commands, so there is nothing you could pass arguments to.

You could get around this by telling the shell to interpret its stdin as if it was a file:

plink -T ... $SHELL /dev/stdin arg1 arg2 arg3 < hello.sh
grawity
  • 501,077