Whatbox Logo

Wiki > Cron

Cron is a time-based scheduler for *nix systems. It allows you to run programs and commands automatically at specified times.

Scheduling Tasks

  1. Connect to your seedbox through SSH
  2. Open your crontab file crontab -e
  3. Enter the jobs you want to schedule in the editor (one per line)
  4. Hit Ctrl-x to exit. Press Y then Enter to save changes.

Job Syntax

The format for crontab entries is * * * * * command

From left to right, each field means:

1Minute (0-59)
2Hour (0-23)
3Day of month (1-31)
4Month (1-12, Jan, Feb, ...)
5Day of week (0-7) 0,7=Sunday, 1=Monday ...
or Sun, Mon, Tue, Wed, Thur, Fri
6Command to execute
  • A comma is used to specify a list of values (1,3,5)
  • A dash is used to specify a range of values (1-5 means 1,2,3,4,5)
  • A slash is used to skip the given number of values (*/12 means "every 12")
  • An asterisk is used to specify all values

Example: 0 12 * * * command would run the specified command every day at noon

Here are some handy aliases to replace the time fields for common cases:

@rebootRun once after reboot
Run once a year (0 0 1 1 *)
@monthlyRun once a month (0 0 1 * *)
@weeklyRun once a week (0 0 * * 0)
@dailyRun once a day (0 0 * * *)
@hourlyRun once an hour (0 * * * *)

Example: @reboot command will run the specified command if your server is restarted


Most Linux distributions provide directories /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, and /etc/cron.monthly, along with a default system-wide crontab file that invokes scripts contained in those directories at the frequency implied by their names.

With user-based crontab files, as used for your slot on whatbox, you have to deal with crontab syntax, as documented above.

While it's completely optional, it's possible to simulate the more convenient system-wide approach you would have if you had root-level access.

First, create some directories to contain scripts to run periodically. At the shell prompt, type the following:

mkdir -p ~/cron/hourly
mkdir -p ~/cron/daily
mkdir -p ~/cron/weekly
mkdir -p ~/cron/monthly
mkdir -p ~/cron/reboot

Then use crontab -e (as described above) to add the following lines to your crontab file:


@hourly  ( cd ~ && run-parts --report ~/cron/hourly )
@daily   ( cd ~ && run-parts --report ~/cron/daily )
@weekly  ( cd ~ && run-parts --report ~/cron/weekly )
@monthly ( cd ~ && run-parts --report ~/cron/monthly )
@reboot  ( cd ~ && run-parts --report ~/cron/reboot )

Once you've set this up, you can simply put scripts into those folders, and they will be run on the corresponding schedule.

Again, this is entirely optional, purely as a convenience.