我想使用Fabric为远程服务器上的用户设置密码。你知道吗
假设我有一个名为“john”的用户,我想为他设置一个默认密码“123”。你知道吗
理想情况下,我想这样做:
run 'passwd john' on remote machine
detect when linux prompts for 'Enter new UNIX password:'
automatically enters the password
detect when linux prompts for 'Retype new UNIX password:'
automatically reenters the password
这就是我尝试过的:
result = run('passwd {}'.format(username))
此语句的问题是,当Linux提示输入密码时,不会捕获“result”。它只在输入密码后返回。你知道吗
有没有一种方法可以自动执行这样的交互式提示?你知道吗
您可以使用
fexpect
进行交互式提示。你知道吗你可以使用prompts
相关问题 更多 >
编程相关推荐