O comando interact
no expect
here-doc foi o problema. Eu precisava esperar pelo EOF:
#! /bin/bash
# this function runs a command like 'ssh' and provides the password
function with_password {
expect << END
set timeout 900
spawn $2
expect *assword:*
send -- $1
expect EOF
END
}
# run "long_running_command" on the remote server
with_password my_password "ssh my_user@some-server long_running_command"
# rsync some data to the remote server
with_password my_password "rsync /some/dir my_user@some-server:/remote/dir"
# run some other random command
with_password my_password "ssh my_user@some-server some_other_command"
O comando interact
parece funcionar algumas vezes quando o comando ssh / rsync fechou a entrada na hora correta (talvez?), mas não era confiável.