开发者

How to sudo as a different user inside a script?

I have a wrapper script which calls two scri开发者_如何学Gopts aaa.sh and bbb.sh. These two scripts should be executed as different users as

sudo -H -u user1

. /user/bin/scripts/aaa.sh

sudo -H -u user1

. /user/bin/scripts/bbb.sh

but the sudo command can't be executed inside a script. Need help...


If you just want to switch users, you should use 'su' not sudo, right?

su user1 -c ./user/bin/scripts/aaa.sh

(that is unless you actually do need elevated privileges)


sudo can be used inside a script, but is the user that executes this script actually allowed to use sudo? Check your /etc/sudoers file.


sudo can be used only if the user name is mapped in /etc/sudoers file as mentioned above. But he may not have the complete priveleges as compared to su user.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜