You misunderstand how the -m
switch works.
This is just a way to get plink
to load commands to send to the server from a local file.
The file is NOT downloaded and executed on the remote server (with arguments).
The content is read locally and sent to the server and executed there as if you entered it in a (remote) command line. You cannot give him arguments.
The workaround is to generate the file "on the fly" locally before running plink
from the 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, rather than building it locally, prepare it on the server (as @MarcelKuiper suggested) and only run the script through Plink.
plink.exe -ssh username@host -pw gbG32s4D/ "./myscript.sh %1"
In this case, when we execute only one command, you can pass it on the Plink command line, including arguments. You do not need to use the -m
switch with a temporary file.
source share