Tente isto:
#!/usr/bin/env expect
set timeout 12
set date [timestamp -format "+%d-%B-%Y"] ;# don't need to call out to date
cd /backup ;# use the built-in cd command
# need to use Tcl syntax for the for loop, not shell syntax
for {set i 0} {$i < 8} {incr i} {
spawn sh -c "ssh host001n < ./backup.py > /backup/dbbackup-$file-$date.txt"
# more DRY
expect {
"Enter passphrase for key '/root/.ssh/id_rsa':" {
send "pass\r"
exp_continue
}
"Password:" {send "pass\r"}
eof
}
}