Table of Contents
Creating Cron jobs
Cron jobs are perfect for repetitive tasks that need to be run on every hour, day, week, or month.
From the Shell
Cron jobs are stored in a file, known as crontab (short for cron table). The syntax is as follows:
* * * * * command to be executed min, hour, day of month, month, day of week, command to be executed
To create a new crontab, or edit the existing crontab for the user currently logged in:
crontab -e
If you add tasks to this crontab, then the process will be owned by the user which is currently logged in.
If you are
EDITOR environment variable is not set, then you your crontab will be loaded in the vi text-editor. If you prefer to use another text editor, such as nano, add the following to your .bashrc file:
export EDITOR=nano
To display your crontab:
crontab -l
To remove all cron jobs (remove the entire crontab):
crontab -r
From Virtualmin
To set up a Crob job on your account, do the following:
- Sign in to Virtualmin (see Account logins and important URLs).
- Click Webmin in the upper-left hand corner, the System, then Scheduled Cron Jobs.
- Click Create a new scheduled cron job.
- Enter the full command to run (including command arguments) into the Command field. Don’t forget to specify full paths to all binaries (e.g.
/usr/local/bin/phpinstead of justphp). - Enter a textual description into Description. This is optional but will help you identify cron jobs later on.
- Select an execution schedule. The default setting will create a cron job that executes every hour. The options that you select from the list fields will set a time when the job will execute (unless you have the All option select which ignores the particular select list).
- When you are done, click Create.