Stop 03 · Linux & Scripting BasicsTopics · 7/9

Cron Jobs & Scheduling

Part of the Cloud Computing Roadmap

In short

Backups at 2 a.m., cleanup every Sunday, a report on the first of each month. You don't set alarms for these. You tell cron once, and it never forgets.

Scheduling scripts or commands to run automatically at specified times or intervals — used constantly for backups, cleanup tasks, and recurring maintenance on cloud VMs.

The mascot on a bicycle with milk cans delivers a milk packet at a doorstep at sunrise.

Think of it like this

The milkman who never misses

The doodhwala rings your bell at 6 a.m. every day, without you calling him. On Sundays he also brings paneer. You told him the schedule once. Cron is that milkman for scripts: give it a time pattern and a command, and it shows up on time.

Watch it happen

Reading 30 2 * * 1-5

30
0
minute
2
1
*
2
*
3
1-5
4

1/5First field is the minute: 30.

The big ideas

What you need to know

Five time fields

minute, hour, day of month, month, day of week. A * means every value.

Cron has a tiny PATH

Cron runs with very few environment variables. Use full paths like /usr/bin/python3 in your jobs.

Capture the output

Redirect output to a log file with >> job.log 2>&1, or you won't know when a job fails.

systemd timers are the alternative

On modern systems, systemd timers do the same job with logs in journalctl and better retry options.

See it in code

Walk through the code

bash
1crontab -e      # edit your user's cron jobs2crontab -l      # list them3 4# Every day at 2:30 a.m.: back up the database530 2 * * * /home/riya/bin/backup.sh >> /home/riya/backup.log 2>&16 7# Every 15 minutes: check disk space8*/15 * * * * /usr/local/bin/check-disk.sh9 10# 9 a.m. on the 1st of every month110 9 1 * * /usr/bin/python3 /opt/reports/monthly.py

1/4crontab -e opens your personal schedule in an editor. -l prints it.

Use a site like crontab.guru to double-check a schedule before saving it.

Save yourself the pain

Common mistakes

Oops

Testing a script in your terminal, then being surprised it fails silently in cron.

Do this instead

Cron has a different PATH and no shell profile. Use absolute paths and log the output to find errors.

Oops

Forgetting the server's timezone, so a '2 a.m.' job runs at 7:30 a.m. IST.

Do this instead

Check with timedatectl. Many servers use UTC, so convert your times or set the timezone deliberately.

Your mission

Schedule your first job

~15 min

Quick check

What does the cron schedule 0 */6 * * * mean?

Go deeper

  1. 1Write a crontab entry to run a script on a schedule (e.g. daily at midnight).
  2. 2Learn to read cron's 5-field time syntax without needing to look it up every time.
  3. 3Compare cron on a VM to a cloud-native scheduled task service (e.g. EventBridge Scheduler) conceptually.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge