Monday, May 14, 2012

Cron Job

buat file a.txt di /tmp/a.txt

1.Cron job seting online :
http://www.corntab.com/pages/crontab-gui

2.root# crontab -e

[isi dengan yg ada di atas #1]
CONTOH cronjob tiap menit:
*/1 * * * * su - oracle -c /tmp/script-backup.sh

CONTOH cronjob tiap jam 2 pagi:
00 02 * * * /tmp/backup.sh

3.JANGAN LUPA RESTART CRON  !
/sbin/service crond restart
 
4. isi script-backup.sh adalah=
/bin/touch /tmp/a.txt ==>utk penanda bahwa script di execute
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_HOME
ll > /tmp/aa.txt
Cron job tidak berfungsi, maka lakukan ini untuk cek:

Verify that root's crontab does anything at all by running a simple
command every minute.  Eg. use 'crontab -u root -e' to add this
line to the root crontab:

    */1 * * * * /usr/bin/touch /tmp/foo

Then if you do 'ls -l /tmp/foo' you should see the timestamp changing
every minute.  Remember to remove this line once you're done testing.

If it doesn't, check that cron is enabled and running.  It is enabled
by default in /etc/defaults/rc.conf.

Examine /var/log/cron -- everything cron tries to run should be logged
there.

However, I suspect that the problem is the standard gotcha when using
cron.  Scripts run from cron get a very minimal environment.  In
particular you *will* need to set the PATH explicitly at the top of
your script. Something like this generally suffices:

    PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/sbin:/usr/sbin:/usr/local/sbin
    export PATH

Or else use fully qualified paths for any programs you call from the
script.

This is the primary cause of programs that work fine under test when
run from your login account but that do not work when run from cron.

No comments:

Post a Comment