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
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?
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:
You got the idea.