问题描述
我目前正在使用期望的密码来传递,所以我的脚本可以自动运行没有我不得不一遍又一遍坐在相同的密码和周围型。
I am currently using expect to pass in passwords so my scripts can run automatically without me having to sit around and type in the same password over and over again.
重要提示:请不要如何大的安全风险,这是还是我应该如何使用SSH密钥,我想,如果我可以用这些,但是设置我有工作不允许对此发表评论。
Important: Please don't comment about how big of a security risk this is or how I should be using ssh keys, I would use those if I could, but the setup I have to work with doesn't allow it.
我的code如下所示:
My code looks like the following:
#!/bin/sh
PASS=mypassword
/usr/bin/expect -c "
spawn python Tools/python/install.py
expect -nocase \"password:\" {send \"$PASS\r\"; interact}
"
我的问题是,install.py提示输入相同的密码了十几次,看来只能指望自动填补了第一次提示输入密码。
The problem I have is that install.py prompts for the same password a dozen times, it appears expect only auto fills the password for the first prompt.
有没有修改的行为,使其在密码填写所有的12次和方式不只是第一次?
Is there a way to modify the behavior so that it fills in the password all 12 times and not just the first time?
推荐答案
您必须做一点编程。幸运的是,答案是pretty简单:
You have to do a little programming. Fortunately the answer is pretty simple:
#!/bin/sh
PASS=MyPassword
export PASS
/usr/bin/expect -c '
spawn python Tools/python/install.py
expect {
-nocase "password:" {
send "$env(PASS)\r"
exp_continue
}
"somthing_else_that_indicates_you're_ready_to_interact"
}
interact
'
- 清理壳报价有点太。
Cleaned up the shell quoting a little too.
这篇关于庆典:不期望有多个密码提示的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!