Connect to your server via SSH. To edit your cronjobs, type
crontab -e in the shell.
- please be aware that your crontab has to end with a new newline, other the last job wont be executed
&>to your job will discard any returns of the job
- when inserting
MAILTOfirstname.lastname@example.org the begin of the crontab you will receive all returns of the cronjobs executed
- Cronjobs should use a locking mechanism that makes sure jobs are only executed once. This locking can be achieved by the application, the script you´re executing or with the usage of
flock. More details regarding locking can be found in the following support article: Locking mechanism for cronjobs
The times in the crontab are as followed (for more see link at the end of the article):
┌───────────── Minute (0 - 59) │ ┌───────────── Hour (0 - 23) │ │ ┌───────────── Day of month (1 - 31) │ │ │ ┌───────────── Month (1 - 12) │ │ │ │ ┌───────────── Day of week (0 - 6) │ │ │ │ │ * * * * * /Pfad/Programmname
* acts as wildcard for every minute / hour/ etc.
Open a URL with
curl (every 5. minute in every hour):
5 * * * * flock -n /tmp/lockfile.curl.job -c 'curl https://www.mydomain.ch/cron/run &> /dev/null'
Execute a script every four hours at the full hour. The script must be executable:
0 */4 * * * flock -n /tmp/lockfile.bash.job -c '/home/www-data/scripts/refresh_cache.sh &> /dev/null'
Start a script every wednesday at 0:30:
30 5 * * 3 flock -n /tmp/lockfile.bash.job -c '/home/www-data/scripts/weekly_report.sh &> /dev/null'
More explanations about the syntax and more examples can be found at the execellent Wikipedia page about cronjobs: Cronjobs