简体   繁体   中英

How to Use two different users in bash scripting

Hi everyone, I am writing a bash script on RedHat V5.1. In this script i have to run one command using dbAdmin and right after that i have to switch again to root user to run the other commands. Can anybody tell me how i can do this in bash scripting.

Thanks in advance....

You need to run your script as root.Then in any part of code just do this:

su - dbadmin -c "command"

Replace command with whatever you want to run under dbadmin user.

This is exact way how redhat init scripts run services under specific users, eg. oracle DB

Try using the SUDO command to switch between root and your dbAdmin account.

http://ubuntuforums.org/showthread.php?t=826935

http://linux.die.net/man/8/sudo

# command1 ; command2 ; sudo -u dbAdmin command3 ; command4 ; command5

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.

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