What is a Cron Job? Print

  • 0

A cron is a time-based scheduler which runs a command or script on your server automatically. Cron jobs are used for scheduling jobs (commands or scripts) to run periodically at fixed times, dates, or intervals.

It is basically a task scheduler daemon (or process) that runs under a Linux / Unix-like OS. It wakes up every minute and checks planned tasks in CRON TABLE aka crontab. Crontab is a configuration file containing shell commands to run periodically on a given schedule.

Before you start, lets have a look at a few examples of cron job time scheduling and the allowed cron job operators:

┌───────────── min (0 – 59)

│ ┌────────────── hour (0 – 23)

│ │ ┌─────────────── day of month (1 – 31)

│ │ │ ┌──────────────── month (1 – 12)

│ │ │ │ ┌─ day of week (0 – 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat)

│ │ │ │ │

│ │ │ │ │

* * * * *  /path/to/your/script.sh

* * * * * => Run every minute
0 * * * * => Run every Hour
0 0 * * * => Run every midnight
0 0 0 * * => Run every Month
0 0 0 0 * => Run every Weekdays

 

 

You can also use one of these special strings in place of the time/date fields.

Entry Description Equivalent to Example
@yearly (or @annually) Run once a year at midnight on January 1 0 0 1 1 * @yearly php /home/example_username/mail.php
@monthly Run once a month at midnight on the first day of the month 0 0 1 * *  @monthly php /home/example_username/mail.php
@weekly Run once a week at midnight on Sunday morning 0 0 * * 0  @weekly php /home/example_username/mail.php
@daily (or @midnight) Run once a day at midnight 0 0 * * * @daily php /home/example_username/mail.php
@hourly Run once an hour at the beginning of the hour 0 * * * * @hourly php /home/example_username/mail.php
@reboot Run at startup (of the cron daemon) @reboot @reboot php /home/example_username/mail.php


Was this answer helpful?

« Back