Task scheduling is the process of automatically running commands, scripts, or programs at specific times or intervals without human intervention. Instead of manually executing a task every day, hour, or week, a scheduler handles it for you.
Learn how to build robust apps and software.
Examples of tasks that need scheduling:
At the operating system level (especially Linux and Unix), the most popular scheduler is Cron.
Learn how to code at your own pace.
A Cron Job is a scheduled task that is executed by the cron daemon (a background service) at predefined times.
Cron is time-based, meaning it triggers tasks based on minutes, hours, days, months, and weekdays.
A cron job is defined using five time fields followed by a command:
* * * * * command_to_run
| | | | |
| | | | └── Day of week (0–7, Sunday = 0 or 7)
| | | └──── Month (1–12)
| | └────── Day of month (1–31)
| └──────── Hour (0–23)
└────────── Minute (0–59)
Example:
0 2 * * * /home/user/backup.sh
This means:
Run backup.sh every day at 2:00 AM.
| Pattern | Meaning |
|---|---|
* * * * * | Every minute |
0 * * * * | Every hour |
0 0 * * * | Every day at midnight |
0 0 * * 0 | Every Sunday |
0 9 * * 1-5 | Every weekday at 9 AM |
*/10 * * * * | Every 10 minutes |
Cron eliminates repetitive manual work. Once scheduled, tasks run reliably.
Jobs run at exact times, reducing human error.
Used for:
In modern web applications, cron jobs are used to:
Example:
While system cron is powerful, many frameworks provide built-in schedulers:
These tools:
| Cron | Job Queues / Schedulers |
|---|---|
| Time-based | Event-based or time-based |
| Simple | More complex |
| OS-level | Application-level |
| No retry logic | Built-in retries & failure handling |
| No UI | Often have dashboards |
In production systems, cron often triggers job queues instead of doing heavy work directly.
Example with logging:
0 1 * * * /usr/bin/python3 /app/cleanup.py >> /var/log/cleanup.log 2>&1
Think of cron like a digital alarm clock for your server:
Cron Jobs and Task Scheduling are foundational to automation in software systems:
In short:
If your system does anything repeatedly, reliably, and on time, a scheduler is working behind the scenes.
Latest tech news and coding tips.
A SOC Analyst (Security Operations Center Analyst) is one of the frontline defenders of an organization’s cybersecurity…
Most image upload systems assume one thing: the user has a stable internet connection. That assumption…
Imagine a user submits a form while their internet connection suddenly disappears. Normally, the request…
Cybercriminals don't always announce their presence. Many compromises are designed to remain unnoticed for weeks…
For years, jQuery was everywhere. If you were building websites in the 2010s, there was a…
Few things halt a developer’s flow faster than seeing the dreaded word: CONFLICT. A Git merge…