Cron is the Linux system for repeated scheduled tasks. Below are a few examples on how to use cron, what the fields mean, and how they work.
List out Cron Jobs for Current User
1 | crontab -l |
Edit Cron Jobs for Current User
1 | crontab -e |
* * * * * * /path/to/command | | | | | | | | | | | | | + /path/to/your/command | | | | | +-- Year (range: 1900-3000) | | | | +---- Day of the Week (range: 1-7, 1 is Monday, 7 is Sunday) | | | +------ Month of the Year (range: 1-12) | | +-------- Day of the Month (range: 1-31) | +---------- Hour (range: 0-23) +------------ Minute (range: 0-59)
Crontab Column Meanings
Minute Hour Day_of_the_Month Month_of_the_Year Day_of_the_Week Year /your/command
Examples
Everyday at 7 am
1 | 0 7 * * * /your/command |
Everyday at 9:30 am
1 | 30 9 * * * /your/command |
Everyday at 9:30 am, Monday Through Friday
1 | 30 9 * * 1,2,3,4,5 /your/command |
1st Day of the Month at 12:30 am
1 | 30 0 1 * * * /your/command |
Every Tuesday at Midnight
1 | 0 0 * * 2 * /your/command |
Every Friday at Midnight
1 | 0 0 * * 5 * /your/command |
Every 2 Minutes
1 | */2 * * * * /your/command |