Tag Archives: Crontab

Home / Crontab
1 Post

As a relative newbie I was confronted with the phenomenon of crontab to automate all kinds of jobs on my Linux driven NAS. I somehow never remembered how the format of a crontab line must be read. There are masses of sites that explains this. I felt the need to collect those information and put it into one convenient place: here.

Let’s take the following crontab line as an example:

1    0    *    *    *    root    sh /volume1/backup/backupMySql.sh

This line starts a backup script to backup a MySql database server. It does this with the root account and runs daily at 0:01 (12:01 AM).

The cron line syntax is mm hh dd MMM DDD user task where:

  • mm is the minute (0..59)
  • hh is the hour (0..23)
  • dd is the day in the month (1..31)
  • MMM is the month (jan, feb, … or 1..12)
  • DDD is the day in the week (sun, mon, … or 0..7 where 0 and 7 being both Sunday)

The following values are also valid:

  • * : a every unit (0, 1, 2, 3, 4…)
  • 5,8 : at unit 5 et 8
  • 2-5 : units 2 to 5 (2, 3, 4, 5)
  • */3 : every 3 units (0, 3, 6, 9…)
  • 10-20/3 : every 3 units, from 10th to 20th (10, 13, 16, 19)

If you take a closer look to the crontab line example, you see that the values are divided by some space. On Synology’s DiskStation it’s preferred to use a TAB as a divider. However a space is also allowed.

After you changed your crontab, witch can be found on the DiskStation at /etc/crontab, you have to restart the cron demon in an SSH shell with:

/usr/syno/etc/rc.d/S04crond.sh stop
/usr/syno/etc/rc.d/S04crond.sh start