Reputation: 980
I am writing a script to transfer a TCL file from a server to a remote system. each file can take ~ 2 hours to transfer. The reason I am using -re .
is so that during the progress it will match anything and update the timeout. So in 10 seconds, if there is no change, then it will end the script. So far I have this script:
set timeout 10
expect {
-re ".*assword*." {
send "${password}\r\r"
exp_continue
} "lost connection" {
set success2 0
set success1 0
} "100%" {
puts "File Transfer successful\n"
set success1 0.5
exp_continue
} -re . {
exp_continue
} timeout {
set success2 0
set success1 0
} -re ".*closed by remote host" {
set success2 0.5
}
}
# IF success1 + success2 = 1, then the transfer was successful.
The problem is that this only works sometimes. After the file is transferred 100%, I have to wait for the message Connection close by remote host
before I can continue with the script. I believe the -re .
matches something before this and ends the script. The time this message takes to display varies. Therefore I get the message could not find variable success2
Upvotes: 0
Views: 715
Reputation: 20798
With expect -re .
you would probably not be able to match -re ".*closed by remote host"
even you put this pattern before -re .
. Can you expect
the NN%
string? For example:
set timeout 60 ;# more timeout since you're scp'ing big files
expect {
-re ".*assword*." {
send "${password}\r" ;# why do you use ``\r\r''?
exp_continue
} "lost connection" {
set success2 0
set success1 0
} "100%" {
puts "File Transfer successful\n"
set success1 0.5
exp_continue
} -re {[0-9]{1,2}%} {
exp_continue
} timeout {
set success2 0
set success1 0
} -re ".*closed by remote host" {
set success2 0.5
} eof {
set success2 0.5
}
}
I'm not sure how you're spawn
ing scp
. My scp
does not output the closed by remote host
message. Maybe the -re ".*closed by remote host"
part is not necessary so you can just keep the eof
part.
Upvotes: 3