0

我正在尝试编写一个脚本来自动登录服务器,运行几行命令(安装 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"

}

whereservers.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
4

1 回答 1

2

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

于 2018-07-06T23:42:57.400 回答