This discussion is archived
8 Replies Latest reply: Jan 28, 2013 1:10 PM by Dude! RSS

Crontab Job

973374 Newbie
Currently Being Moderated
Hi Gurus,
i am using Oracle 10g with Linux, i want to schedule a job using Cron tab.
So, pls clarify me where i have to pur the cron file(specify the directory) and what will be the extension of the file .sh or....
Pls help

Regards,
Rajeev
  • 1. Re: Crontab Job
    881508 Journeyer
    Currently Being Moderated
    To edit or add something to crontab you just need to issue crontab -e from your command prompt. And then add your schedule and required scripts into this file and save it. Check below link for more details.

    http://www.pantz.org/software/cron/croninfo.html

    Also this is not a security question. Next time try to create your question into the correct group to get the answer fast.
  • 2. Re: Crontab Job
    ShishirTekadeR Explorer
    Currently Being Moderated
    use below command for enable crontab in Linux env.
    vi /etc/cron.allow

    mention oracle10g user name then u need to open contab using "crontab -e" command

    use below link for details....
    http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/
  • 3. Re: Crontab Job
    clementeOTN Explorer
    Currently Being Moderated
    Hi

    If the job is a "shell script" (bash/pdksh/zsh) , the extension can be .sh , but in linux the extension doesn't care, the file must be executable, but you can name it as you wish

    The correct place for "use binaries" in a unix system is +/usr/local/bin+ . However, it may be safer to create subdirectory under your $ORACLE_HOME (for example $ORACLE_HOME/jobs )thus, other users can not see the contents of the scripts and know what they are or how many are



    P.D maybe this post must be in linux section instead the security one
  • 4. Re: Crontab Job
    973374 Newbie
    Currently Being Moderated
    Hi,
    I have created a backupfile "rmanbkp.sh" and also edited in the cron file with the help of this comman
    crontab -e , the script which i have written like:

    20 9 * * * /etc/cron.daily/rmanbkp.sh (this is the backup file name, here backup output location not given because FRA is already set)

    but it's not running, i think the path is wrong.
    pls help

    Regards,
    Rajeev
  • 5. Re: Crontab Job
    EdStevens Guru
    Currently Being Moderated
    970371 wrote:
    Hi,
    I have created a backupfile "rmanbkp.sh" and also edited in the cron file with the help of this comman
    crontab -e , the script which i have written like:

    20 9 * * * /etc/cron.daily/rmanbkp.sh (this is the backup file name, here backup output location not given because FRA is already set)

    but it's not running, i think the path is wrong.
    pls help

    Regards,
    Rajeev
    Where is your file 'rmanbkp.sh' located? You are telling cron it is located in /etc/cron.daily. While cron is certainly capable of locating and executing files in that directory, that is most definately NOT where you should be putting them. Please re-read DementeOTN's comment about placement of your scripts.

    You also need to be aware that when cron executes a script, it DOES NOT execute the owner's profile. So if you are depending on any environment variables (like, oh, say ORACLE_HOME and ORACLE_SID) your script must set them itself.
  • 6. Re: Crontab Job
    973374 Newbie
    Currently Being Moderated
    Hi,
    then rmanbkp.sh i have to pur at home location.

    Regards,
    Rajeev
  • 7. Re: Crontab Job
    EdStevens Guru
    Currently Being Moderated
    970371 wrote:
    Hi,
    then rmanbkp.sh i have to pur at home location.

    Regards,
    Rajeev
    And your "home location" is .. what? By default, it should be '/home/oracle'. Do not confuse the concept of the ORACLE_HOME location, with the 'home' directory of the os user 'oracle'. Two completely different concepts and should be two completely different locations.

    So, if you have a script 'rmanbkp.sh' located in '/home/oracle' , and you want it to run at 0920 every day, then your crontab entry should be
    20 9 * * *  /home/oracle/rmanbkp.sh
    BTW, while '/home/oracle/' is a far better location than '/etc/cron.daily' it's still not ideal. I'd put it in a subdirectory of either /home/oracle or (better) $ORACLE_BASE. Subdirectory names that make sense like 'bin' or 'scripts'., ie:
    /home/oracle/scripts
    /home/oracle/bin
    /u01/app/oracle/scripts
    /u01/app/oracle/bin
  • 8. Re: Crontab Job
    Dude! Guru
    Currently Being Moderated
    This type of question is normally solved easily by doing a Google search and bit of research. I guess today is your lucky day ;-)

    The /etc/cron.daily and other cron directories in /etc/ are reserved for root. They are used for system maintenance scripts.

    Any crontask for Oracle Database must be executed as the Oracle database owner and should run in the Oracle account userspace, usually user "oracle". You need to set the Oracle envirionment because cron does not load any user profile.

    Assuming you have a default Oracle installation, the following example should give you a bit of a head start:

    Login as user oracle:
    su - oracle
    Create a file, e.g.: backup_inc0 with the following contents:
    #!/bin/bash
    # File: /home/oracle/backup_inc0
    #
    # Set up Oracle shell environment
    #
    ORACLE_SID=test
    ORAENV_ASK=NO
    source /usr/local/bin/oraenv -s
    #
    rman target / <<-EOF
    backup as compressed backupset incremental level 1 database \
    plus archivelog delete input;
    exit
    EOF
    Set appropriate privileges:
    $ chown oracle:dba /home/oracle/backup_inc0
    $ chmod u+x /home/oracle/backup_inc0
    Create the following Crontab entry to run the script every Sunday at 10 PM:
    $ crontab -e
    Enter the following:
    0 22 * * 6 /home/oracle/backup_inc0
    I hope this information was useful.

Legend

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