简体   繁体   English

如何使用Fabric Python在远程服务器上将Shell脚本作为Postgres运行

[英]How to run shell script as postgres on remote server using fabric python

How can I enter postgres sudo user to run a script in a specific folder? 如何输入postgres sudo用户以在特定文件夹中运行脚本? The reason I have to cd into the script is because it requires me to run it in that particular directory. 我必须进入该脚本的原因是因为它要求我在该特定目录中运行它。

Would love inputs and comments on my approach and see if there is a better way. 希望能对我的方法提供意见和建议,看看是否有更好的方法。

The following is the fabric script I came up with. 以下是我想到的结构脚本。 but it does't allow me to enter postgres user mode. 但是它不允许我进入postgres用户模式。

@task
def run():
    with sudo('-su postgres'):
        with cd('/home/XXX/www/my_app'):
            run('somescript.sh', use_sudo=True)

Thank you! 谢谢!

doc of sudo command sudo命令的文档

So you can switch user with sudo command like following: 因此,您可以使用sudo命令切换用户,如下所示:

sudo("mkdir /var/www/new_docroot", user="www-data")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM