1834066 Members
2820 Online
110063 Solutions
New Discussion

Re: at and cron issues

 
SOLVED
Go to solution
Timothy Czarnik
Esteemed Contributor

at and cron issues

Hey all,

We have a job that shuts down an Oracle database. When we run the job via cron, we get permissions problems and the script doesn't work (it runs, it just doesn't shut the database down). When we use the "at" command, it works. We used both cron and at as root. "at" works, cron doesn't. Any ideas?

-Tim
Hey! Who turned out the lights!
9 REPLIES 9
harry d brown jr
Honored Contributor
Solution

Re: at and cron issues

The problem is the environment variables that are used for cron are very minimal. To get oracle to work, you can "source" in your normal root stuff, like .profile, .cshrc or .kshrc, etc.
Live Free or Die
Herve BRANGIER
Respected Contributor

Re: at and cron issues

Hi

Just an idea : I think you can verify you
have the same environment with at and cron.
I think that cron use a minimal environment.
In this case you need to modify your environment
(variables to export) before execution.

HTH

Herv?

A. Clay Stephenson
Acclaimed Contributor

Re: at and cron issues

Hi Tim:

The problem is that the cron environment is very sparse. You need to set and export ORACLE_SID,ORACLE_HOME,PATH, etc. either explicitly in your script or better still as as '.' sourced file in your script. The best way is to create scrits which set and export these variables. Do not put an exit statement in these scripts because both your .profiles and your cron scripts should source these file
e.g. . /usr/local/bin/oraenv.sh
If it ain't broke, I can fix that.
Timothy Czarnik
Esteemed Contributor

Re: at and cron issues

Thanks for the quick responses! Are you saying that the cron environment variables are different than the at environment variables even when the same user (namely root in this case) uses cron and at?

-Tim
Hey! Who turned out the lights!
linuxfan
Honored Contributor

Re: at and cron issues

Hi Timothy,

cron by default sets a minimal set of environment variables

HOME=user's-home-directory
LOGNAME=user's login id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh

where as "at" sets up the environment to match the environment when the at command was given.

So for your script to work correctly in cron, its always a good idea to source your .profile or the file containing your environment variables.

For more information check the man pages of at, cron and crontab

-Ramesh
They think they know but don't. At least I know I don't know - Socrates
Timothy Czarnik
Esteemed Contributor

Re: at and cron issues

Hey all,

Thanks again for the help! I am a firm believer in the points system, and do not normally give out 10's to more than 1 person in a post, but the speed and accuracy with which you all nailed the answer left me no choice.

Thanks again!

-Tim
Hey! Who turned out the lights!
Magdi KAMAL
Respected Contributor

Re: at and cron issues

Hi Timothy,

You need to set your environement variables at the begining of your crontab job by the following command :

#. /.profile

This will set all variables needed for your cron job ( of course it should work in interactive mode ! ).

Magdi

T G Manikandan
Honored Contributor

Re: at and cron issues

Hello,
1.add the script directory to your path variable.
2.Use the crontab of oracle user to shutdown the database.
crontab -e oracle
Then add your script of shutdb.
If it doesn't work then take the entry of the crontab file and add it again,then try it out.

for ex: your database shutdown script(shutdb) is like
echo "enter the sid for oracle :\c"
read ORACLE_SID
export ORACLE_SID
/opt/app/oracle/product/8.1.5/bin/svrmgrl << !
connect internal;
shutdown immediate;
!
Thanks
G Manikandan

Steve Faidley
Valued Contributor

Re: at and cron issues

You made the comment "namely root" was the user.
If you have a script run by root to start and stop oracle such as in /sbin/init.d you should have it su to oracle;
"su - oracle -c /path_of_oracle_script"


If it ain't broke, let me have a look at it.