This discussion is archived
4 Replies Latest reply: Nov 16, 2012 5:47 AM by 787789 RSS

Cron job giving trouble, Please help me out

787789 Newbie
Currently Being Moderated
Hi All,

Could you please help me out..It is really messing me for no fault of mine i believe.

I am trying to schedule a job using crontab, It runs but looks like it either doesn't access the monitor.sql or it fails to produce output as you could see out is 0, but when i run the shell script directly it produces output perefectly.
Here is my script:

oracle-PPOST@pebsdbf01 /home/oracle # crontab -l
23 14 * * * /u01/app/oracle/product/10.2.0/admin/monitor.sh > /u01/app/oracle/product/10.2.0/admin/date.log

-rwxr-x--- 1 oracle oinstall 75 Nov 16 13:58 monitor.sql
-rwxr-x--- 1 oracle oinstall 62 Nov 16 14:19 monitor.sh

===========

monitor.sql

set time on
select sysdate from dual;
exit
/


========

monitor.sh

sqlplus "apps/appsdcs" @/u01/app/oracle/product/10.2.0/admin/monitor.sql

Here is an output:
-rw-r--r-- 1 oracle oinstall 0 Nov 16 14:23 date.log
  • 1. Re: Cron job giving trouble, Please help me out
    Brian Bontrager Expert
    Currently Being Moderated
    Don't assume your .profile is applied when cron launches monitor.sh; it may not have a path to sqlplus. You can call a .profile from the cron command, but I find it easier to maintain if I put everything I need for the environment in monitor.sh.

    If you add 2>&1 to the end of the crontab entry your errors will also be redirected to date.log and you may have another clue what is failing.
  • 2. Re: Cron job giving trouble, Please help me out
    Fran Guru
    Currently Being Moderated
    modify your monitor.sh, and insert the full path where is sqlplus, for example:

    u01/app/oracle/product/10.2.0/db_1/bin/sqlplus -s apps/appsdcs @/u01/app/oracle/product/10.2.0/admin/monitor.sql
  • 3. Re: Cron job giving trouble, Please help me out
    EdStevens Guru
    Currently Being Moderated
    784786 wrote:
    Hi All,

    Could you please help me out..It is really messing me for no fault of mine i believe.

    I am trying to schedule a job using crontab, It runs but looks like it either doesn't access the monitor.sql or it fails to produce output as you could see out is 0, but when i run the shell script directly it produces output perefectly.
    Here is my script:

    oracle-PPOST@pebsdbf01 /home/oracle # crontab -l
    23 14 * * * /u01/app/oracle/product/10.2.0/admin/monitor.sh > /u01/app/oracle/product/10.2.0/admin/date.log

    -rwxr-x--- 1 oracle oinstall 75 Nov 16 13:58 monitor.sql
    -rwxr-x--- 1 oracle oinstall 62 Nov 16 14:19 monitor.sh

    ===========

    monitor.sql

    set time on
    select sysdate from dual;
    exit
    /


    ========

    monitor.sh

    sqlplus "apps/appsdcs" @/u01/app/oracle/product/10.2.0/admin/monitor.sql

    Here is an output:
    -rw-r--r-- 1 oracle oinstall 0 Nov 16 14:23 date.log
    As others mentioned but left incomplete ... when a script is started by cron, it DOES NOT invoke the user's .profile (or .bash_profile, as the case may be). It is the responsibility of the script itself to set ALL of the environment variables it needs. At the top of that list will be PATH, ORACLE_BASE, ORACLE_HOME, ORACLE_SID.
  • 4. Re: Cron job giving trouble, Please help me out
    787789 Newbie
    Currently Being Moderated
    Thanks a lot ..I took ur suggestions ...setup environment variable inside cron job..it worked fine..thanks a lot...

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points