Crontab (cron table) is a Linux utility that allows you to run commands or scripts automatically at specified intervals. Here’s how you can configure crontab on a Linux system:
- Open the terminal and type the following command to open the crontab file for editing:
crontab -e
- The crontab file will open in the editor specified by the
VISUAL
orEDITOR
environment variable. If neither is set, it will default tovi
. - To add a new cron job, add a new line in the following format:
* * * * * /path/to/command
The first five fields represent the following information:
- Minute (0-59)
- Hour (0-23)
- Day of the month (1-31)
- Month (1-12)
- Day of the week (0-7, where both 0 and 7 represent Sunday)
For example, to run a command every day at 3 PM, the line would look like this:
0 15 * * * /path/to/command
- Save and close the crontab file.
- Verify that the new cron job has been added by using the following command:
crontab -l
This will list all the cron jobs that are currently configured.
Note: When specifying paths in crontab, make sure to use the full absolute path, rather than a relative path.