Operating System - HP-UX
1752489 Members
5558 Online
108788 Solutions
New Discussion юеВ

Need help with su cmd in a shell script

 
SOLVED
Go to solution
Chris Elmore
Frequent Advisor

Need help with su cmd in a shell script

Aloha Sharp HP Folks,

I have written a very simple & basic shell script which I hope will allow me to cron my Oracle 9i startup (and shutdown) times. When I run these commands as root from within the root's shell manually, they work just fine. But when I run the very same commands in the root context from within my simple shell script below, it seems to get "stuck" on the su - oracle command and everything breaks down from there. My shell script will just wait in my Oracle home dir, and when I exit out from su, the shell script continues processing with the . .profile line but the dbstart is useless without the Oracle home environment parameters. Is there something I am missing with trying to su from within a shell script? My OS is HP-UX 11.0. Thanks in advance for anyone who can help steer me in the right direction with this.

Very Respectfully,
Chris Elmore

x----------x cut here x----------x

clear
cd /
su - oracle
. .profile
dbstart
mailx -s"Oracle 9i has started!" user@email.com < /export/chris/oracle_startup.txt
"Life is love and love is life"
3 REPLIES 3
Steven E. Protter
Exalted Contributor
Solution

Re: Need help with su cmd in a shell script

You ned to do this:

/usr/bin/su - oracle -c "oracle command line"

This gets you the environment and issues the command within the double quotes.

Thats how we do what you wish to do.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Hoang Chi Cong_1
Honored Contributor

Re: Need help with su cmd in a shell script

Hi

In general, the script that you want to su another user and execute a command is:

su - -c

For example: If you want to execute a script or command like: /home/oracle/script/check_pef.sh
Then the command:
su - oracle -c "sh /home/oracle/script/check_pef.sh"

Do you realy want to make script file? Give me your email, I have script to shutdown and start Oracle database and it is running now in my system....but for Oracle 8i.

Regard,
HoangChiCong
Looking for a special chance.......
Chris Elmore
Frequent Advisor

Re: Need help with su cmd in a shell script

Aloha Folks,

You are the best. That switch was exactly what I needed. I tested the script and it works now. Oracle 9i has a dbstart and dbshut script that automates the startup and shutdown of Oracle and Listener respectively, and the only catch was to get it to run under cron within the Oracle login context. You gave me the tool I needed to make that happen. Again, I really appreciate you sharing your expertise. Take care.

Very Respectfully,
Chris Elmore
"Life is love and love is life"