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