CronTab


Contents [hide]

  1. 1. What is the CronTab?
  2. 2. CronTab Syntax
    1. 2.1 Operators
    2. 2.2 Fields
    3. 2.3 Commands
    4. 2.4 Example of a CronTab File
  3. 3. Location of the CronTab File
  4. 4. Display the CronTab Settings
  5. 5. Change the CronTab File

1.  What is the CronTab?

Cron is a time-based scheduling service in Unix-like computer operating systems. 'cron' is short for 'chronograph'.

Generally, the schedules modified by crontab are enacted by a daemon, crond, which runs constantly in the background and checks once a minute to see if any of the scheduled jobs need to be executed. If so, it executes them. These jobs are generally referred to as cron jobs.

2.  CronTab Syntax

Each line of a crontab file represents a job and follows a particular format as a series of fields, separated by spaces and/or tabs. Each field can have a single value or a series of values.

2.1  Operators

There are several ways of specifying multiple date/time values in a field:

  • The comma (',') operator specifies a list of values, for example: "1,3,4,7,8"
  • The dash ('-') operator specifies a range of values, for example: "1-6", which is equivalent to "1,2,3,4,5,6"
  • The asterisk ('*') operator specifies all possible values for a field. For example, an asterisk in the hour time field would be equivalent to 'every hour' (subject to matching other specified fields).

There is also an operator which some extended versions of cron support, the slash ('/') operator (called "step"), which can be used to skip a given number of values. For example, "*/3" in the hour time field is equivalent to "0,3,6,9,12,15,18,21".

So "*" specifies 'every hour' but the "*/3" means only those hours divisible by 3.

2.2  Fields

# +---------------- minute (0 - 59)
# |  +------------- hour (0 - 23)
# |  |  +---------- day of month (0 - 30)
# |  |  |  +------- month (1 - 12)
# |  |  |  |  +---- day of week (0 - 6) (Sunday=0 or 7)
# |  |  |  |  |
  *  *  *  *  *  command to be executed

2.3  Commands

Commands to be executed can be any shell commands, like calling programs or running shell scripts (see OS/OS Documentation for more details).

2.4  Example of a CronTab File

Here's an example of a CronTab file on the QNAP:

# m h dom m dow cmd
0 4 * * * /sbin/hwclock -s
0 3 * * * /usr/local/sbin/ImR_all -soft /Qmultimedia

=> The first job runs the shell command "/sbin/hwclock -s" every day at 04:00 hrs.

3.  Location of the CronTab File

Note that several Crontab are stored in different locations on the QNAP. The "master CronTab" is located in /mnt/HDA_ROOT/.config/crontab. In order to make permanent changes, you need to edit this file
Some Linux directories are mapped into RAM (see MountPoints). Thus they will be erased on the next reboot.

Location of all Crontab files on the QNAP:

Root DirectoryDeviceLink / CommentMaster
/mnt/ext/usr/bin/crontabHDD/bin/busybox 
/mnt/HDA_ROOT/.config/crontabHDDMASTER, hidden
/mnt/HDA_ROOT/rootfs_2_3_6/etc/config/crontabHDDMASTER
/mnt/HDA_ROOT/rootfs_2_3_6/tmp/cron/crontabs/adminHDD/etc/config/crontab 
/tmp/cron/crontabs/adminRAM/etc/config/crontab 
/usr/bin/crontabRAM/bin/busybox 
/var/lib/pcmcia/cron/crontabs/adminRAM/tmp/cron/crontabs/admin 
/var/pcmcia/cron/crontabs/adminRAM/tmp/cron/crontabs/admin 
/var/run/cron/crontabs/adminRAM/tmp/cron/crontabs/admin 
/var/spool/cron/crontabs/adminRAM/tmp/cron/crontabs/admin 
/var/tmp/cron/crontabs/adminRAM/tmp/cron/crontabs/admin 
/etc/default_configRAMcontains fewer datasets, not updated
/etc/config/crontabRAM/mnt/HDA_ROOT/.config/crontab 
/mnt/HDA_ROOT/rootfs_2_3_6/tmp/cron/crontab.1237HDDsometimes not there 
/tmp/cron/crontab.1237RAMsometimes not there 
/var/lib/pcmcia/cron/crontab.1237RAMsometimes not there 
/var/pcmcia/cron/crontab.1237RAMsometimes not there 
/var/run/cron/crontab.1237RAMsometimes not there 
/var/spool/cron/crontab.1237RAMsometimes not there 
/var/tmp/cron/crontab.1237RAMsometimes not there 

4.  Display the CronTab Settings

To display the current CronTab file (show the settings), logon to your QNAP using PuTTY and enter the command crontab -l.

5.  Change the CronTab File

=> See How To/Change CronTab for details.