python - Fabric:本地命令用法

标签 python fabric

我想在本地机器上执行一个需要 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/

相关文章:

python - 使用带有命名空间的结构,有没有办法指定每个文件 env.shell

python - fabric 1.0.0 中的高 CPU 使用率

python - Fabric:如何提示用户在 env.roledefs 中定义的主机之间进行输入?

python - 在 MongoEngine 中增加一个 IntField

填充列表时 Python 内存泄漏 - 如何修复?

python - 根据域对大电子邮件文件进行排序显示错误

python - 使用 VectorAssembler 计算平均值和最大值

python - Fabric - 如何动态提供 ssh 密码

python - IE8 未在 Windows7 上从 Python 代码上的 Selenium (webdriver) 启动

python - 使用 python Fabric 的 Linux 机器的目录大小