【发布时间】:2019-03-17 03:06:34
【问题描述】:
我正在尝试自动化一些ssh 进程。我有我的期望代码。但是我的 Expect 代码只回显/打印出命令。它实际上并没有运行命令。
#!/usr/bin/expect -f
set timeout 10
set usrnm "aaaaaa"
set pwd "pppppp"
set addr1 "xxx.cloud.xxx.com -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
set addr2 "xxx.xxxx.xxxx.com"
spawn ssh $usrnm@$addr1
expect {
"(yes/no)?" {send "yes\r";exp_continue}
"password: " {send "$pwd\r"}
}
expect "*#"
send "ssh $usrnm@$addr2\r"
expect {
"(yes/no)?" {send "yes\r";exp_continue}
"password:" {send "$pwd\r"}
}
expect "*#"
send "cd /tmp/myself/folder\r"
expect "*#"
send "./run_engine.sh test.py\r"
expect eof
#interact
如果我这样做了
expect my_expect.exp
它只是打印命令:
spawn ssh aaaaaa@xxx.cloud.xxx.com -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
(10s later)
ssh aaaaa@xxx.xxxx.xxxx.com
(10s later)
cd /tmp/amz337/COAFALV
(10s later)
./run_engine.sh test.py
(exit)
我的脚本有什么问题?
【问题讨论】:
-
一些不切实际的建议:使用 SSH 密钥身份验证会 a) 更安全,b) 允许您使用纯 shell 脚本而不是
expect,并且 c) 因此更容易维护。跨度>
标签: bash shell ssh automation expect