Crontab Every 2 Hours (0 */2 * * *)
Schedule a cron job to run every 2 hours at the top of the hour. Uses the step operator in the hour field for bi-hourly execution.
Detailed Explanation
Running a Cron Job Every 2 Hours
The expression 0 */2 * * * runs at minute 0 of every 2nd hour: midnight, 2 AM, 4 AM, 6 AM, 8 AM, 10 AM, noon, 2 PM, 4 PM, 6 PM, 8 PM, and 10 PM.
Field Breakdown
| Field | Value | Meaning |
|---|---|---|
| Minute | 0 | At minute 0 |
| Hour | */2 | Every 2nd hour |
| Day of Month | * | Every day |
| Month | * | Every month |
| Day of Week | * | Every day |
Step Operator in the Hour Field
The */2 step in the hour field works the same way as in the minute field. Starting from 0 (midnight), it selects every other hour: 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22.
Variations
You can use different step values in the hour field:
0 */3 * * *— Every 3 hours (0, 3, 6, 9, 12, 15, 18, 21)0 */4 * * *— Every 4 hours (0, 4, 8, 12, 16, 20)0 */6 * * *— Every 6 hours (0, 6, 12, 18)0 */8 * * *— Every 8 hours (0, 8, 16)0 */12 * * *— Every 12 hours (0, 12)
Execution Count
This schedule runs 12 times per day, providing a moderate frequency for tasks that do not need hourly processing.
Use Case
Suited for database index optimization, aggregation pipeline runs, CDN cache purging, certificate expiry checks, backup verification, and batch processing jobs where hourly is too frequent and daily is too sparse.