Pipe output with expect spawn

放肆的年华 提交于 2019-12-01 10:52:09

"spawn" the 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

If you can't setup keys, you can put the "tar ... | ssh ..." line into another script and call it with spawn, just pass the required parameter

.i.e:

spawn anotherscript.bash $sdir $port $login $host

You got the idea.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!