Run shell script (with parameters) on Windows command line via Plink

二次信任 提交于 2019-11-27 05:09:49

You misunderstand how the -m switch works.

It is just a way to make plink load the commands to send to the server from a local file.

The file is NOT uploaded and executed on the remote server (with arguments).

It's contents is read locally and sent to the server and executed there as if you typed it on a (remote) command line. You cannot give it arguments.


A workaround is to generate the file on the fly locally before running plink from a batch file (say run.bat):

echo echo %1 > script.tmp
plink.exe -ssh username@host -pw gbG32s4D/ -m script.tmp

Then run the batch file with the argument:

run.bat 5

The above will make the script execute echo 5 on the server.


If the script is complex, instead of assembling it locally, have it ready on the server (as @MarcelKuiper suggested) and execute just the script via Plink.

plink.exe -ssh username@host -pw gbG32s4D/ "./myscript.sh %1"

In this case, as we execute just one command, you can pass it on Plink command line, including the arguments. You do not have to use the -m switch with a (temporary) file.

Have you tried putting the command and argument in quotes:

i.e. -m "C:\myscript.sh 5"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!