0 */3 * * * Crontab

4 min read Jul 03, 2024
0 */3 * * * Crontab

*Crontab: 0 /3 * * * Explained

Crontab is a powerful tool in Linux-based systems that allows users to schedule tasks to run at specific intervals. One of the most common and versatile cron expressions is 0 */3 * * *, which we'll break down and explain in this article.

Breaking Down the Expression

The cron expression 0 */3 * * * consists of five asterisks, each representing a different field:

  • 0: minute
  • */3: hour
  • *: day of the month
  • *: month
  • *: day of the week

Let's dive deeper into each field:

Minute Field (0)

The 0 in the minute field specifies that the task should run at the beginning of the hour. This means that the task will execute at 0 minutes past the hour, every hour.

Hour Field (*/3)

The */3 in the hour field is where the magic happens. The */ is called a step value, which specifies that the task should run every 3 hours. This means that the task will execute at 0:00, 3:00, 6:00, 9:00, 12:00, 15:00, 18:00, 21:00, and so on.

Day of the Month Field (*)

The * in the day of the month field is a wildcard character, which means that the task will execute every day of the month, regardless of the day number.

Month Field (*)

The * in the month field is another wildcard character, indicating that the task should run every month, without any restrictions.

Day of the Week Field (*)

The final * in the day of the week field is yet another wildcard character, which means that the task will execute every day of the week, including Sundays, Mondays, and so on.

When Will the Task Run?

With the cron expression 0 */3 * * *, the task will run:

  • Every 3 hours
  • At the beginning of the hour (0 minutes past the hour)
  • Every day of the month
  • Every month
  • Every day of the week

In summary, the task will execute at 0:00, 3:00, 6:00, 9:00, 12:00, 15:00, 18:00, 21:00, and so on, every 3 hours, 24/7/365.

Conclusion

The 0 */3 * * * cron expression is a powerful tool for scheduling tasks to run at specific intervals. By understanding each field and how they interact with each other, you can create custom scheduling scenarios to automate your tasks and workflows.

Related Post


Featured Posts