Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Oracle Script from cron 1

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Hello,

In testing a simple shell script to shutdown Oracle9i on my Solaris 8 system I find it runs fine from the command line as my oracle user. When I add it to a cron job via my oracle user account (via crontab -e) however, it does not run from cron.

My script:
#!/bin/sh
sqlplus /nolog @shutdown.sql


Note: the script sqlplus calls (shutdown.sql) is in the $HOME directory.

My cron entry in my account for oracle:
00 15 * * * $HOME/oracle.shutdown


What can you recommend?


Thanks,

Michael42
 
from the command line, did you run it by doing $HOME/oracle.shutdown?

Also, are you getting any sendmail errors after it runs?



Blue [dragon]

If I wasn't Blue, I would just be a Dragon...
 
You need to establish the Oracle parameters: ORACLE_HOME, ORACLE_SID. You could probably add a line to run your oracle user's .profile before running the shutdown command.
 
The environment that cron starts this job from doesn't have $HOME defined. You just need to specify an explicit path to the script in your crontab. Something like...
Code:
00 15 * * * /home/oracle/scripts/oracle.shutdown
Hope this helps.

 
Agree with all of the above, but make sure you set the environment variables in the script to be exactly the same as those when running it interactively. In particular, check the $PATH in interactive mode and replicate it early in your shutdown script. HTH.
 
You can run your script by the "root" crontab:
0 15 * * * su - ora_user -c "$HOME/scripts/oracle.shutdown"

In this way the ora_user .profile will be executed, and all the env var will be settled up
 
YES!!!

>>You can run your script by the "root" crontab:
>>0 15 * * * su - ora_user -c "$HOME/scripts/oracle.shutdown"

All your suggestions were good, sbix's was the clincher though.

Thanks everyone - I learned a lot from this.

Michael42
 
Out of curiosity, was your oracle user's shell c?
I had a similar problem with a user creating files from a script he was running from his cron. The script created a file for users of the same group to access. Running the script with #!/bin/csh worked fine (rw-rw-r-- permissions umask was set to 002) , but #!/bin/sh caused the permissions to be off (rw-r--r--). It was obviously not reading the user's profile. I don't know if this is a Solaris thing or not?

 
>> Out of curiosity, was your oracle user's shell c?

Yes - but I try to run all my scripts using #!/bin/sh so as they run in all (most) environments.




Thanks,

Michael42
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top