CRON is not working perfectly

I scheduled a cron job to run @ 1:00 as follows ,
00 01 * * * /app/cbf/CLIF/version-1.0.0.0/scripts/archival.sh

Please find the archival.sh script.

But cron is throwing a mail stating sqlplus command not found
So can anybody suggest what might be the problem ???

Where do you have the definition of the function "execute_sql" used in the script?

If the script is unable to find the location of the sql command then it will throw this error,try giving the full path of the sql.

Are you able to run the script locally ie not from a cron?

Thanks
Nagarajan G

yes i am able to run , standalone this script on my loacl m/c with out any error .

Please the attached script where execute_sql is defined

This because in your script the PATH was not defined.

As you have defined,

ORACLE_BIN=$ORACLE_HOME/bin  ; export ORACLE_BIN
function execute_sql
{
db_var="$1"
v_cnt=`$ORACLE_HOME/bin/sqlplus -s $CLIF_DB_USRNM/$CLIF_DB_PWD@$CLIF_DB_NAME << ENDSQL | sed -e "s/Connected\.//" -e "/^$/d"
set pagesize 0 feedback off verify off heading off echo off  serveroutput on size 10000
whenever sqlerror exit 1
--@'$var1'
$db_var
commit;
exit ;
ENDSQL`
db_var=""
}

Please try by providing full path to "sqlplus" command in the execute_sql function as above.

Thanks
Nagarajan G

ok..thanx a lot...i will try this option out...and let u know the status

Or you can better try setting the PATH variable in the script where 'execute_sql' function is defined(sqlplus is used).

export PATH="$PATH:$ORACLE_BIN"

This will add the utilities in Oracle home's bin to the path in which it will search when it encounter 'sqlplus' or 'sqlldr'

With Regards
Dileep Pattayath

i just wanna to know...
why the path for oracle/sqlplus needs to set in my coding level of profile values???knowing that these are already there in .profile of that particular user which invokes the cron.

i have added these values just to know that every parameter(global n local) are properly set while running my cron, but of no use ..now i am going to add this PATH variable , let see what happens.

But my understanding is that cron is executed on-behalf of root.So the .profile file of the user was not be effective.
You can create a file under the name profile.env and source it in each script as "source profile.env".This will be effective.

I dont think that the values exported via users .profile may be available for the cronjob.So its always better to specify the explict path as used in your script,the only explicit path which was missed in your script is that of the "sqlplus",so it is quite simpler to specify the explicit path in the execute_sql function instead of going for exporting PATH in your script as you have defined the ORACLE bin path.

Thanks
Nagarajan G

thanks a lot ennstate and DILEEP410 for your kind help .
Now my cron is working fine .

Hi All,

 I have a shell script which does decryption\(calling subscript\) and other s necessary tasks. It runs fine when I run localy.But when I placed in CRONTAB, the decrption part is not working.

Here I attached dec.sh (decryption script) and credit_settle.sh(main script).

I appreciate, if anyone provide valuable suggestions to fix this issue.

Thanks
arun

Hi All,

 I have a shell script which does decryption\(calling subscript\) and other s necessary tasks. It runs fine when I run localy.But when I placed in CRONTAB, the decrption part is not working.

Here I attached dec.sh (decryption script) and credit_settle.sh(main script).

I appreciate, if anyone provide valuable suggestions to fix this issue.

Thanks
arun

When executing from crontab the environment is not set (.profile is not executed before).
A solution is to execute the .profile in the crontab command line, for example :

00 01 * * * . ~/.profile; /path/to/credit_settle.sh

Jean-Pierre.

Is it showing any errors, please mention.Normally as aigles says crontab is executed from different uid permissions,so that it won't set the environment by calling .profile since it's user specific.But i think you are not using .profile,isn't it?

Regards
Dileep