How to crontab

See How to jobs to schedule Oracle Jobs
#Save actual schedualtions:
    crontab -l > cron.txt
Backup actual schedulation:
    cp -p cron.txt crontab_20040525.txt
Edit:
    vi cron.txt
Save:
    crontab cron.txt
Check:
    crontab -l
Redirect the output
The error to another file:
... 2>/tmp/error.log
 
Remember to set user variables in your scripts, because crontab doesn't catch them automatically.

Just copy them from $home/.profile and paste them after #!/bin/sh, for example:

possible shells are:
#!/bin/ksh
#!/bin/bash
#!/bin/sh
#!/bin/ksh
export ORACLE_SID=pvgg3
export ORACLE_BASE=/home/oracle
export TNS_ADMIN=$ORACLE_BASE/admin/$ORACLE_SID/network/admin
export ORACLE_HOME=$ORACLE_BASE/product/9.2.0.4 
export PATH=$ORACLE_HOME/bin:$ORACLE_BASE/admin/scripts:$PATH
export TMPDIR=/home/oracle/tmp
export TMP=$TMPDIR
export TMP_DIR=$TMPDIR

SCRIPTFILE=script.sql
cat << EOF > $SCRIPTFILE
.......

Examples

Oracle Statspack crontab
#Crontab line, is executed only if the source file is found, this is useful when running in cluster with
#only a single node active
0,15,30,45 * * 1-2 * test -f /home/oracle/stats.ksh && /home/oracle/stats.ksh > /home/oracle/stats.nohup 2>&1

#/home/oracle/stats.sql
begin
statspack.snap(i_snap_level=>6);
end;
/
exit;

#/home/oracle/stats.ksh, remember "chmod +x stats.ksh"
#!/bin/ksh
export ORACLE_SID=AL12
export ORACLE_BASE=/app/oracle
export TNS_ADMIN=$ORACLE_BASE/admin/$ORACLE_SID/network/admin
export ORACLE_HOME=$ORACLE_BASE/product/9.2.0
export PATH=$ORACLE_HOME/bin:$ORACLE_BASE/admin/scripts:$PATH
export TMPDIR=/tmp
export TMP=$TMPDIR
export TMP_DIR=$TMPDIR
sqlplus "perfstat/perfstat" @stats.sql

 

Every hour of every day
00 0-23 * * * /home/oracle/admin/scripts/xp_take_stats.sh pvgg1 VPO > 
/home/oracle/admin/scripts/xp_take_stats.log

At 02:00 AM on 03/07/2004 (dd/mm/yyyy)
00 02 03 07 * /home/oracle/admin/pvgg1/scripts/statsCaricamenti.sh > statsCaricamenti.out

Every 5 minutes only 27/1/2005 and 28/1/2005
#Raccolta stataement per sqlreg
00,05,10,15,20,25,30,35,40,45,50,55 * 27,28 01 2005

At 00:00 each monday
00 * * * 1

Every day from monday to sat at 1
0 1 * * 0-6

Every day
02 4 * * *

Every week
22 4 * * 0