I currently have a tcl script that is sending a .tar.gz to a remote server.

spawn scp -r "file_to_send.tar.gz" $user@$host:/
set timeout 10

spawn ssh $user@$host
expect "password: "
send -- "$passwd\r"

send -- "tar -zxvf /file_to_send.tar.gz\r"
sleep 1

However, it seems like my extract doesn't work because the scp didn't fully complete. Is there a way to programmatically check when the scp is complete?

  • Can that comment be completed in 10 seconds? Aug 31, 2016 at 18:39

1 Answer 1


You can wait for the first spawn to finish by following it with

expect eof

or if you prefer you can capture and test the return code

catch wait result
if [lindex $result 3] { send_user "fail\n";  exit 1 }
send_user "ok\n"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .