Python结构如何为用户提示发送密码和是/否 [英] Python fabric How to send password and yes/no for user prompt
本文介绍了Python结构如何为用户提示发送密码和是/否的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个包含多个主机的fabfile。
我正在自动执行我的实验。当我运行命令sudo adduser --ingroup hadoop hduser时,它会询问以下内容。
- 新的unix密码
- 确认密码。
- 全名
- 房间,Ph等 这个信息是否正确? Y / N
我想将所有这些信息作为脚本的一部分传递给用户。我怎么能这样做?
谢谢
纳瓦兹
解决方案
为什么你不用管道?
例如,对于自动接受,那只是输出一个永不停息的流。
是| rm * .txt
在您的案例中:
local('echo'your_super_password \''| sudo adduser --ingroup hadoop hduser')
I have created a fabfile with multiple hosts.
I am automating my experiment. When i run the command "sudo adduser --ingroup hadoop hduser" it will ask for the following.
- New unix password
- confirm Password.
- Full Name
- Room,Ph,etc
- is this information Correct? Y/N
I would like to pass all this information as part of script without prompting user. How can i do this ?
Thanks
Navaz
解决方案
Why didn't you just use pipes?
For example, for an automated auto accept, just use yes, that just outputs a neverending stream of y.
yes | rm *.txt
in your case:
local('echo 'your_super_password\n' | sudo adduser --ingroup hadoop hduser')
这篇关于Python结构如何为用户提示发送密码和是/否的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文