Execute oracle commands with root login

I have oracle installed on a solaris system. Follwing is the problem we are facing and i couldn't find a good solution anywhere:

We need to execute some commands in oracle to take oracle database backups. For that it is required to be logged in as an oracle user. I want these backups to be automated and the most probable solution is using cron jobs. But the problem is that the oracle command which i want to execute under root login does not executed. Displays an error message for the command, because root does not have access to those commands. Is there a way to execute oracle commands without logging into oracle and without typing in password and simply execute as root. I will need a simple script file to do something like below
<All this is under root, the script file is stored under root>

foo.sh
su -oracle
<there is no prompt for password>
< backup command>
mailx -s "job done"


Does  su -oracle -c <backup command> work in this case?




janu_sAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jlevieCommented:
As root, 'su -oracle -c <backup command>' should work, provided that the <backup command> doesn't require a password.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yuzhCommented:
It should be:
    su - oracle -c <backup command>

    Need a WHITE SPACE between - and oracle.
0
jlevieCommented:
True...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.