URGENT: cron job not running the sqlplus command in shell script

cron job not running the sqlplus command in shell script but the shell script works fine from command line..

Cronjob:

5 * * * * /home/dreg/script.sh

script.sh:

#!/bin/ksh
/oracle/u000/app/oracle/product/10204/GEN/bin/sqlplus -s <user>/<pass>@<sid/home/dreg/sqlscript.sh

sqlscript.sh:

select <statements>

Script.sh works fine when ran from /home/dreg
cronjob runs the script.sh runs all comamnds in the script except just not executing the sqlplus.

It is littile URGENT ..appreciate if some one can response.

Thanks
Dreg

Without seeing the script cannot help much...

Make sure you use full paths for your commands and logs, check cron log output, make sure script has execute permissions for the cron user.

read this FAQ.

>>>Without seeing the script cannot help much...

I have listed the script details above for your reference.

>>>Make sure you use full paths for your commands and logs, check cron log output, make sure script has execute permissions for the cron user.

Yes full path has been specified like you see in the above code.
Script has execute permissions to all

dreg

can some please help me?

#!/bin/ksh
/oracle/u000/app/oracle/product/10204/GEN/bin/sqlplus -s <user>/<pass>@<sid/home/dreg/sqlscript.sh

The highlighted is not a full path.

#!/bin/ksh
/oracle/u000/app/oracle/product/10204/GEN/bin/sqlplus -s <usr>/<pass>@<sid></home/dreg/sqlscript.sh

Hope this is what you are asking..

If the file's actually in /home/dreg/sqlscript.sh then yes. Given the crazy path it had earlier though I'm skeptical.

Would there is any thing that i need to check ?

I am not getting any clue on why the cron is not executing the sqlplus

Thanks
dreg

verify that the script works under the cron user id out in the shell normally.

personally, i never like executing a script directly through cron and always
make sure that a specific environment is sourced into the shell running that command.

for example:

1 * * * * /acus/bin/cron_env.sh some-shell.cmd with some arguments

and cron_env.sh looks like:

. /acus/bin/set_env.sh
$*

i'm willing to bet you have environment variable issues. something's not getting set through cron.

verify that the crontab user under this job has connect permissions and read permissions tothe database and tables you're accessing, write permissions also, if necessary.

verify that every directory in your fullpaths are searchable by this user.

Is sqlscript.sh actually in /home/dreg/sqlscript.sh ?

thats corrrect.

what is the error message you're getting from the cron job?

have you compared the environmental variables from the normal login shell
to the cron shell used?

you know these are totally different, right?

for example, i believe ORACLE needs to access certain database information through the oranames.tns file which is stored
under an environmental variable ORACLE_ADMIN_DIR or something like that. . . .

this variable would not be set in your cron environment, unless you explicitly did so.

>>>what is the error message you're getting from the cron job?

I am not getting any error message ..it is just that the cron is overlooking the sqlplus line in the script and executes everything else

>>>for example, i believe ORACLE needs to access certain database information through the oranames.tns file which is stored
under an environmental variable ORACLE_ADMIN_DIR or something like that. . . . this variable would not be set in your cron environment, unless you explicitly did so

If i execute the script from absolute path from command line ..everything works..so i believe all the ORACLE parameters are set in .profile..

Is there anything that needs to be set specifically for cron job to work?

5 * * * * . ~/.profile && /home/dreg/script.sh

that's what i'm telling you, Ikea....

the .profile is NOT SOURCED IN DURING CRON.

you must explicitly do so within a shell, within your cron command.

try putting everything into another script like this:

quirks_new_script.sh:


. /home/user/.profile
/home/dreg/script.sh

vger's recommendation will only work if there are no "sh" incompatible commands within the .profile.

  • edit * -- in fact, on my machine, cron does not interpret ~ correctly.

What I'm saying is this:

cron is run under the Bourne shell.
Your script is who-knows-which shell.

Therefore, you must create something that sets up the environment explicitly for your ORACLE script to run.
Do not assume ANYTHING is set up.
Remember: the user's .profile IS NOT USED THROUGH cron.

1 Like

If a script executes from the command line but has issues in cron, it is possible that your environment is not getting set properly. With Oracle in particular, you need : ORACLE_SID, ORACLE_HOME set in your environment and ORACLE_HOME/bin must be concatenated to your path. This may be done for you by sourcing "oraenv" which typically resides in /usr/local/bin (check with your DBA). If you look in your .profile, it may contain the necessary steps to establish your environment. You can add these environment settings to your script, or you can source a separate file to set them.

an example. If your database SID is "prod1" and Oracle Home is /u01/app/oracle/product/10.2.0 then add the following to your Korne or Bourne shell:

ORACLE_SID=prod1
export ORACLE_SID
ORACLE_HOME=/u01/app/oracle/product/10.2.0
export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin
export PATH

that should get you started.

It worked.

Thanks a lot lot :slight_smile: appreciate it.

I will give points to quirkasaurus. Thanks