What is a Cron Job?
A **Cron Job** is a time-based job scheduler in Unix-like computer operating systems (like Linux and macOS). Users who set up and maintain software environments use cron to schedule jobs (commands or shell scripts) to run periodically at fixed times, dates, or intervals.
Think of it as the "Alarm Clock" for your server. It can be used to run automated backups, clear cache folders, send out daily emails, or update database records automatically.
Understanding Crontab Syntax
The syntax consists of five fields separated by spaces, followed by the command. An asterisk (*) stands for "every".
* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- Day of week (0 - 6) (Sunday=0)
| | | +------- Month (1 - 12)
| | +--------- Day of month (1 - 31)
| +----------- Hour (0 - 23)
+------------- Minute (0 - 59)
Special Characters
- Asterisk ( * ): Matches all values (e.g., every minute).
- Comma ( , ): Separates individual values (e.g., `1,15` in the minute field means run at minute 1 and minute 15).
- Dash ( - ): Defines a range (e.g., `1-5` in weekday means Monday to Friday).
- Slash ( / ): Specifies steps (e.g., `*/5` in minutes means every 5 minutes).
Common Cron Examples
* * * * *: Run every minute.0 0 * * *: Run once a day at midnight.0 2 * * 1: Run at 2:00 AM every Monday.*/15 * * * *: Run every 15 minutes.
How to Setup a Cron Job
If you have SSH access to your server:
- Type
crontab -ein your terminal to edit the cron table. - Paste the line generated by this tool at the bottom of the file.
- Save and exit (in Nano, press `Ctrl+O` then `Enter`, then `Ctrl+X`).
If you use **cPanel**:
- Log in to cPanel and look for "Cron Jobs" under the Advanced section.
- Enter the email address where you want output sent (optional).
- Use the form or paste the command generated here into the command box.
Troubleshooting Tip: Output Muting
By default, cron sends an email to the user every time a job runs. If your job runs every minute, your inbox will explode. To stop this, select the "Mute Output" option in our tool. This appends `>/dev/null 2>&1` to the command, which discards all output and errors.