最佳的方式在批处理脚本远程SSH命令(视窗) [英] Best way to script remote SSH commands in Batch (Windows)

查看:4514
本文介绍了最佳的方式在批处理脚本远程SSH命令(视窗)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待一些脚本批量这将需要在Linux上运行远程SSH命令。我想返回的输出,所以我可以显示在屏幕上,或记录它。

I am looking to script something in batch which will need to run remote ssh commands on Linux. I would want the output returned so I can either display it on the screen or log it.

我试过 putty.exe -ssh用户@主机-pw密码-m command_run 但它并不在我的屏幕上返回任何东西。

I tried putty.exe -ssh user@host -pw password -m command_run but it doesn't return anything on my screen.

任何人这样做过?

推荐答案

腻子 -m 开关需要一个路径到脚本文件作为参数,而不是命令。

The -m switch of PuTTY takes a path to a script file as argument, not command.

参考:<一href=\"http://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter3.html#using-cmdline-m\">http://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter3.html#using-cmdline-m

所以,你有你的指令( command_run )保存到一个纯文本文件(如 C:\\路径\\ command.txt ),并传递到腻子:

So you have to save your command (command_run) to a plain text file (e.g. c:\path\command.txt) and pass that to PuTTY:

putty.exe -ssh user@host -pw password -m c:\path\command.txt

另外请注意,您应该使用的Plink(从腻子套件的命令行连接工具)。这是一个控制台应用程序,所以你可以把它重定向输出到一个文件中(你不能用腻子做)。

Also note that your should use Plink (a command-line connection tool from PuTTY suite). It's a console application, so you can redirect it's output to a file (what you cannot do with PuTTY).

一个命令行语法是相同的,输出重定向补充说:

A command-line syntax is identical, an output redirection added:

plink.exe -ssh user@host -pw password -m c:\path\command.txt > output.txt

请参阅使用命令行连接工具的Plink

类似的问题:结果
自动化在Windows上运行Linux命令使用腻子结果
从一个批处理文件中的P​​link执行命令

Similar questions:
Automating running command on Linux from Windows using PuTTY
Executing command in Plink from a batch file

这篇关于最佳的方式在批处理脚本远程SSH命令(视窗)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆