Python结构如何为用户提示发送密码和是/否 [英] Python fabric How to send password and yes/no for user prompt

查看:126
本文介绍了Python结构如何为用户提示发送密码和是/否的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含多个主机的fabfile。



我正在自动执行我的实验。当我运行命令sudo adduser --ingroup hadoop hduser时,它会询问以下内容。


  1. 新的unix密码

  2. 确认密码。

  3. 全名

  4. 房间,Ph等
  5. 这个信息是否正确? 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.

  1. New unix password
  2. confirm Password.
  3. Full Name
  4. Room,Ph,etc
  5. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆