[英]How can I change users in during my bash script excecution and continue running commands with the new user?
So I'm making an ubuntu bash script for an installation and in the middle of it I have to change users to the postgres user (running sudo su postgres
) then I have to enter postgres shell and run some commands more. 因此,我正在为安装制作一个ubuntu bash脚本,在其中,我必须将用户更改为postgres用户(运行
sudo su postgres
),然后我必须输入postgres shell并运行一些命令。 The problem is that when I change user to the postgres user the commands keeps running with the root user. 问题是,当我将用户更改为postgres用户时,命令将继续以root用户运行。 How can I run these commands with the postgres user?
如何使用postgres用户运行这些命令?
When you run sudo su user
you switch to this users shell, but your script is still in your first root shell, and is waiting for sudo su user
to finish so it can continue. 当您运行
sudo su user
您将切换到该用户shell,但是您的脚本仍在您的第一个root shell中,并且正在等待sudo su user
完成,以便可以继续。
You should run each command for another user like this: sudo -u other_user your_command
您应该像这样为另一个用户运行每个命令:
sudo -u other_user your_command
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.