Tools & Infrastructure

Cron Jobs and Scheduled Tasks

How to make your computer automatically run tasks while you sleep.

Scroll to start

What Is a Cron Job?

A cron job is a task your computer runs on a schedule — automatically, without you needing to be there. Think of it like setting an alarm clock, except instead of waking you up, it tells your server to back up files, send emails, or check for new data.

The word "cron" comes from a Greek word meaning "time." Cron jobs live on servers and run on a schedule you define. You don't have to click anything. The clock takes care of it.

For example, you could set a cron job to run every day at 6am and back up your website's database. While you're sleeping, the server wakes up, copies the data, and saves it somewhere safe — then goes back to sleep.

Why Automation Beats Reminders

Humans are bad at remembering to do things on time. You forget to back up your files. You miss the report that was due Monday morning. A cron job never forgets, never gets distracted, and never shows up late.

For solo builders and small teams, cron jobs are a superpower. They let you automate the boring, recurring stuff — like sending weekly digests, checking if a website goes down, or clearing out old data — so you can focus on the work that actually needs a human brain.

The best part: once it's set up, a cron job runs forever. You do the work once. The computer does it forever.

💡 Key Insight

Every hour you spend automating a recurring task saves you that hour forever. A task that takes 10 minutes a day, automated, saves you 60 hours a year — that's a full work week for just one automation.

Reading a Cron Schedule

A cron job is defined by a schedule written in a special short format. It looks confusing at first, but it's actually pretty simple. Each cron line has five fields separated by spaces:

cron schedule format
# ┌───────────── minute (0–59)
# │ ┌───────────── hour (0–23)
# │ │ ┌───────────── day of month (1–31)
# │ │ │ ┌───────────── month (1–12)
# │ │ │ │ ┌───────────── day of week (0–6, Sun=0)
# │ │ │ │ │
* * * * *   command to run

The asterisks (*) mean "every." Here are some common examples:

01
🌅

Every Morning

0 6 * * *
Every day at 6:00 AM

02
📅

Every Monday

0 9 * * 1
Every Monday at 9:00 AM

03
⏱️

Every 15 Minutes

*/15 * * * *
Every 15 minutes, all day

To set up a cron job, you use a tool called crontab on a server. You open it, add your line with the schedule and the command, save it, and the server handles the rest.

A Backup Script on a Schedule

Here's a simple example of a cron job that backs up a database file every night at 2am. In plain English: "At 2:00am every day, copy the database file and save it with today's date."

crontab -e
# Back up the database every night at 2:00 AM
0 2 * * *   /usr/bin/mysqldump -u root mydb | gzip > /backups/db-$(date +\%Y-\%m-\%d).sql.gz

Break it down: 0 2 * * * means 2:00am every day. The command runs mysqldump to export the database, pipes it through gzip to compress it, and saves it with today's date in the filename.

Modern tools like GitHub Actions, Vercel Cron Jobs, and platform.sh let you set up scheduled tasks without touching a server terminal — just fill in a form and write the code that runs.

Knowledge Check

Test what you learned with this quick quiz.

Quick Quiz — 3 Questions

Question 1
What does a cron job do?
Question 2
What does the cron schedule "0 6 * * *" mean?
Question 3
Why are cron jobs useful for solo builders?
🏆

You crushed it!

Perfect score on this module.