CRON is a time-based job scheduler in Unix-like operating systems, including Linux and macOS. It allows users to schedule tasks (also known as “cron jobs”) to run automatically at specified times or dates.
CRON works by checking the /etc/crontab file and the /etc/cron./ files on a regular basis, and executing commands specified in those files at the specified times. The tasks can be scheduled to run at a specific time, or at regular intervals, such as every hour or every day.
Each line in a CRON file represents a separate task and has the following format:
* * * * * command
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=both 0 and 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
The asterisks in the format above are placeholders for the specific time values. For example, the following CRON job would run the command my_script.sh
every day at 4pm:
0 16 * * * /bin/sh /path/to/my_script.sh
CRON is an essential tool for system administrators, as it allows them to automate routine tasks, such as system backups, software updates, and database maintenance. It can also be used by individual users to automate tasks such as sending emails, generating reports, and cleaning up files.
CRON is highly flexible and configurable, making it a powerful tool for automating tasks on Unix-like systems. However, it’s important to use CRON responsibly and to thoroughly test your scripts before scheduling them to run automatically.