【问题标题】:Run batch file remotely using ssh and copy the result to a text?使用 ssh 远程运行批处理文件并将结果复制到文本?
【发布时间】:2014-12-21 15:30:09
【问题描述】:

我需要使用sshexpect 远程运行批处理脚本并将结果复制到文本文件中。我该怎么做?

这行得通:

 $ ssh -t username@dshost 'D:\scripts\a.bat' >file.txt

但这不是:

#! /usr/bin/expect --
spawn ssh -t username@shost  'D:\\scripts\\a.bat' >file.txt
expect "*assword:*" { send "pwd\r" }    
expect "yes/no"     send "yes\r"
exit

我收到以下错误。

The filename, directory name, or volume label syntax is incorrect.

【问题讨论】:

  • 你试过/d:/scripts/a.bat 吗?
  • 这不是回答你的问题,而是把exit改成expect eof
  • 两个命令中的文件夹名称不同。它找不到脚本s
  • 那是一个错字。我已经编辑了问题中的代码。将退出更改为期望 eof - 仍然不起作用

标签: shell batch-file ssh expect


【解决方案1】:

spawn 是否运行 cmd,如果不是,它是执行重定向的命令。

cmd /c command >file

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    • 2016-05-23
    • 1970-01-01
    • 2015-01-23
    • 1970-01-01
    相关资源
    最近更新 更多