Wiki > Cron
Cron is a time-based scheduler for *nix systems. It allows you to run programs and commands automatically at specified times.
- Connect to your seedbox through SSH
- Open your crontab file
- Enter the jobs you want to schedule in the editor (one per line)
Ctrl-xto exit. Press
Enterto save changes.
The format for crontab entries is
* * * * * command
From left to right, each field means:
|3||Day of month (1-31)|
|4||Month (1-12, Jan, Feb, ...)|
|5||Day of week (0-7) 0,7=Sunday, 1=Monday ... |
or Sun, Mon, Tue, Wed, Thur, Fri
|6||Command 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
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:
|@reboot||Run once after reboot|
|Run once a year (0 0 1 1 *)|
|@monthly||Run once a month (0 0 1 * *)|
|@weekly||Run once a week (0 0 * * 0)|
|@daily||Run once a day (0 0 * * *)|
|@hourly||Run once an hour (0 * * * *)|
@reboot command will run the specified command if your server is restarted
Most Linux distributions provide directories
/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
crontab -e (as described above) to add the following lines to your crontab file:
SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin @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.