我有一个嵌入在bash脚本中的expect脚本:
#! /bin/bash
# this function runs a command like 'ssh' and provides the password
function with_password {
expect << END
spawn $2
expect *assword:*
send -- $1
interact
wait
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"
问题是有时脚本会在等待生成命令时挂起.如果我
将wait命令退出expect脚本,命令将继续在远程上运行
服务器,但bash脚本将继续,我无法知道它何时完成.
为什么我的期望脚本似乎随机挂起?