2

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....

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Yes I agree with @rkosegi you want to use the su -c option, if you use sudo the user must be built into your sudoers list since you're using a RedHat based distribution users are typically not in the sudoers list by default.
3

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.