运行shell脚本(带参数)上通过的Plink Windows命令行 [英] Run shell script (with parameters) on Windows command line via Plink
问题描述
我需要在Linux箱内从Windows远程执行shell脚本
I need to execute a shell script remotely inside the Linux box from Windows
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "Illegal number of parameters"
exit
fi
echo "$1"
下面是我从Windows命令提示符
Here is the command I ran from Windows command prompt
cmd> plink.exe -ssh username@host -pw gbG32s4D/ -m C:\myscript.sh 5
我收到输出
非法数量的参数
有什么办法,我可以通过命令行参数的shell脚本,将远程服务器上执行?
Is there any way I can pass command line parameter to shell script which will execute on remote server?
推荐答案
您误解了如何使用 -m
切换工作。
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.
一个解决方法是从一个批处理文件运行砰砰
(比如的run.bat $ C $本地之前,动态生成的文件C>)
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
以上将使脚本执行 5呼应
在服务器上。
如果脚本是复杂的,而不是在本地组装它,有它准备在服务器上(如@MarcelKuiper建议),并通过执行的Plink只是脚本。还是你需要的参数保存到临时文件:
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. Still you need to save the arguments to a temporary file:
echo ./myscript.sh %1 > script.tmp
plink.exe -ssh username@host -pw gbG32s4D/ -m script.tmp
这篇关于运行shell脚本(带参数)上通过的Plink Windows命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!