Linux 通过 putty.exe 在 Windows 命令行上运行 shell 脚本(带参数)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11001508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:48:27  来源:igfitidea点击:

To run a shell script (with parameters) on Windows command line via putty.exe

linuxbashbatch-fileputty

提问by samantha

I need to execute a batch script which runs the shell script remotely inside the Linux box.

我需要执行一个批处理脚本,该脚本在 Linux 机器内远程运行 shell 脚本。

Now, everything is working fine, but the script fails to execute if I try to give a command line parameterto the shell script.

现在,一切正常,但如果我尝试为shell 脚本提供命令行参数,脚本将无法执行。

Working -> ex

工作 -> 前

C:\temp\Testing>putty.exe -pw "blabla" -m "test-script.sh" [email protected]

C:\temp\Testing>putty.exe -pw "blabla" -m "test-script.sh" [email protected]

But if I try to give arguments it fails to execute. Example:

但是如果我尝试给出参数,它就无法执行。例子:

Not Working

不工作

C:\temp\Testing>putty.exe -pw "blabla" -m "test-script.sh ok-1" [email protected]

C:\temp\Testing>putty.exe -pw "blabla" -m "test-script.sh ok-1" [email protected]

 where ok-1 = command line argument for local script test-script.sh

How can I fix this problem?

我该如何解决这个问题?

采纳答案by bta

Instead of using putty.exe, you can use pscpand plink(utilities that come with PuTTY) to do this. Use a command like this:

putty.exe您可以使用pscpplink(PuTTY 附带的实用程序)来执行此操作,而不是使用。使用这样的命令:

pscp.exe -pw "blabla" test-script.sh [email protected]:/some/path/

to copy the script to the remote server, and then use a command like this:

将脚本复制到远程服务器,然后使用如下命令:

plink.exe -ssh -pw "blabla" [email protected] /some/path/test-script.sh ok-1

to execute it.

执行它。