使用ssh远程运行批处理文件并将结果复制到文本?

时间:2014-10-26 07:40:55

标签: shell batch-file ssh expect

我需要使用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.

1 个答案:

答案 0 :(得分:0)

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

cmd /c command >file