Cron Revisited
Its been a long time i havent done schedule cronjobs in cron. Here’s a refresher..
A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.
* * * * * command to be executed - - - - - | | | | | | | | | +----- day of week ( - 6) (Sunday=) | | | +------- month (1 - 12) | | +--------- day of month (1 - 31) | +----------- hour ( - 23) +------------- min ( - 59) |
cron invokes the command from the user’s HOME directory with the shell, (/usr/bin/sh).
cron supplies a default environment for every shell, defining:
HOME=user’s-home-directory
LOGNAME=user’s-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh
Here is a cron scirpt which svn commits the database every 1am…
[root@dbserver1 ~]# crontab -l #Cron check #* * * * * /bin/date >> /root/date.log #Every 1AM svn commit the database 1 * * * /bin/sh /root/dbbackup.sh > /root/dbbackup.log #Every 6AM Update the date and time from ntpd 6 * * * /usr/sbin/ntpdate .asia.pool.ntp.org > /root/dateupdate.log [root@dbserver1 ~]# more /root/dbbackup.sh #!/bin/sh /bin/date >> /root/dbbackup.log dbfolder=/data/mysqldata/cybersoftbj /usr/bin/svn add $dbfolder/* >> /root/dbbackup.log /usr/bin/svn commit --non-interactive --username ***** --password ***** -m "committed by autosvn cron script" $dbfolder/* >> /root/dbbackup.log /bin/chown -Rf mysql:mysql $dbfolder /bin/chmod -Rf 755 $dbfolder |