Skip to main content

Using the CRON Timer

Using Cron Expressions for Scheduled Tasks

Cron expressions are a way to define when a task or job should run. These expressions consist of five fields representing minutes, hours, day of the month, month, and day of the week. Here's a breakdown:

  • Minute (0 - 59): The minute when the task should run.
  • Hour (0 - 23): The hour when the task should run.
  • Day of the Month (1 - 31): The day of the month when the task should run.
  • Month (1 - 12): The month when the task should run.
  • Day of the Week (0 - 6): The day of the week when the task should run (Sunday = 0).

Example:

Let's say you want to schedule a backup task to run every day at 2:30 AM.

  1. Minute: 30
  2. Hour: 2
  3. Day of the Month: * (every day)
  4. Month: * (every month)
  5. Day of the Week: * (every day of the week)

The cron expression would be: 30 2 * * *

Practical Steps:

1. Identify the Schedule:

Determine how often you want the task to run and at what specific time.

2. Use a UI or Application:

If you're using an application or service, there might be a graphical user interface (UI) where you can set up scheduled tasks. Look for a "Scheduled Tasks," "Cron Jobs," or similar section.

3. Input the Cron Expression:

In the scheduled tasks section, you may find a field asking for a cron expression. Enter the expression based on your desired schedule.

4. Examples:

  1. Every 5 Minutes - */5 * * * *

  2. Every 30 Minutes - */30 * * * *
  3. Every Hour - 0 * * * *
  4. Every 12 Hours - 0 */12 * * *
  5. Every Day - 0 0 * * *
  6. Every Other Day - 0 0 */2 * *
  7. Every Friday - 0 0 * * 5
  8. Every Month - 0 0 1 * *

 

5. Save or Apply Changes:

After inputting the cron expression, save or apply the changes. The scheduled task should now adhere to the specified schedule.