How can I enter postgres sudo user to run a script in a specific folder? 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.
@task
def run():
with sudo('-su postgres'):
with cd('/home/XXX/www/my_app'):
run('somescript.sh', use_sudo=True)
Thank you!
So you can switch user with sudo command like following:
sudo("mkdir /var/www/new_docroot", user="www-data")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.