我想在本地机器上执行一个需要 sudo 的命令。因此,正如文档所建议的那样,我使用了本地命令,但它要求我输入密码。我怎样才能避免这种情况?有什么地方可以保存我的本地机器密码吗?
local('sudo /etc/init.d/tomcat6 start',capture=True)
最佳答案
如果您不打算共享您可以使用的 fabfile:
echo "password\n" | sudo -S /etc/init.d/tomcat6 start
根据 sudo 手册页:
The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. The password must be followed by a newline character.
关于python - Fabric:本地命令用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3941777/