期望命令过早终止

expect commands terminate too early

我正在尝试编写一个脚本来自动登录服务器,运行 几行命令(安装 Anaconda),然后退出。下面的脚本执行得很好,直到 this 行开始正常但突然结束(在仅安装 10 个左右的库之后)并且没有给出任何错误消息。是因为 expect 脚本的超时设置吗?关于如何解决它的任何想法?

#!/usr/bin/expect

set f [open "/Users/user1/Downloads/servers.txt"]
set hosts [split [read $f] "\n"]
close $f

set f [open "commands.txt"]
set commands [split [read $f] "\n"]
close $f

foreach host $hosts {
     spawn ssh -o StrictHostKeyChecking=no USERNAME@$host;
     expect "?assword:"
     send "PASSWORD\r"

     foreach cmd $commands {
        expect "$ "
        send "$cmd\r"
     }

     expect "$ "
     send "exit\r"

}

其中 servers.txt 只是服务器列表,commands.txt 如下:

wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh -O ~/anaconda.sh
bash ~/anaconda.sh -b -p $HOME/anaconda
echo 'export PATH="$HOME/anaconda/bin:$PATH"' >>~/.bash_profile
source .bash_profile

期望脚本自动设置超时= 10。因此,您需要使用 set timeout 120 或任何时间更改脚本开头的超时。