带有预期生成的管道输出 [英] Pipe output with expect spawn

查看:73
本文介绍了带有预期生成的管道输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有用于通过ssh将某些文件复制到其他服务器的脚本.我正在使用tar将文件压缩到farchive上,并从其他计算机上的stdout解压缩.

I have script for copying some files by ssh to other server. I'm using tar for compressing files to on farchive and decompress it from stdout on other machine.

set timeout -1

# user info
set port [lindex $argv 0]
set login [lindex $argv 1]
set password [lindex $argv 3]
set host [lindex $argv 2]

#tar info
set sdir [lindex $argv 4]
set ddir [lindex $argv 5]

spawn tar cf - $sdir | ssh -p $port $login@$host tar xf - -C $ddir

expect "*?(yes/no)" {
    send "yes\r"
}

expect "*?assword" {
    send "$password\r"
}

expect "#" {
    send "ls $ddir -la\r"
}

expect "#" {
    send "exit\r"
}

interact

但是'|'不适用于spawn.我试图找到任何解决方案,但是没有适合我的方法.您能给我一个关于这个问题的建议吗?

But '|' doesn't work with spawn. I tried to find any solution, but there no any suitable way for me. Can you give me an advice for this question?

推荐答案

生成" shell

set timeout -1

# user info
set port [lindex $argv 0]
set login [lindex $argv 1]
set password [lindex $argv 3]
set host [lindex $argv 2]

#tar info
set sdir [lindex $argv 4]
set ddir [lindex $argv 5]

spawn $env(SHELL) 

expect "#" {
    send "(tar cf - \$sdir) | (ssh -p \$port \$login@\$host tar xf - -C \$ddir)\r"
} 

expect -re "(yes/no)" {
    send "yes\r"
}

expect -re "assword" {
    send "$password\r"
}

expect "#" {
    send "exit\r"
}

interact

这篇关于带有预期生成的管道输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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