Thuta Learning
AdvancedDevOps & Toolsbeginner

Scheduling Tasks with Cron

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand Scheduling Tasks with Cron without any of the intimidation
  • Get hands-on practice trying out the commands yourself in the terminal
  • See how these commands actually come in handy on a real server or project

Let's think about it this way for a second

cron is a scheduler daemon (service) that's always running in the background — you write rules in a crontab (cron table) file that say 'run this command at this time.' crontab -e edits your crontab, and crontab -l shows the rules already there. The syntax format is minute hour day month weekday command, and putting * in any field means 'every' — for example, 0 2 * * * /path/to/backup.sh means 'run backup.sh every day at 2am' (0 = minute 0, 2 = hour 2, and * * * = every day/every month/every weekday).

Let's connect this to a real-world scenario

cron is perfect for tasks you need to repeat regularly — things like server backups, log rotation, and database cleanup — no more setting manual reminders and running them by hand. The first time you run crontab -e, it'll ask you to choose a text editor (nano is a beginner-friendly pick) — after that, you just add a rule line and save/close. Since cron jobs run in the background, you won't see their output yourself — if you redirect it (with > or >>) into a log file, you can check back on it later.

Let's try it together in the terminal

text
# crontab -e ထဲမှာ ရေးရမယ့် rule format
# min hour day month weekday  command
0    2    *   *     *        /home/user/backup.sh
*/15 *    *   *     *        /home/user/check-health.sh
0    0    *   *     0        /home/user/weekly-report.sh >> /home/user/cron.log
You should see
Running crontab -l shows the schedule rules you've added.

5-minute try-it

Run crontab -e (or crontab -l) — it might be empty. Then write out a rule line for 'run backup.sh every day at noon' yourself (no need to actually run it, just practice the syntax).

A quick word of caution

Test-run a script yourself in the terminal before adding it to crontab — the cron environment can differ from your terminal environment in some variables.

Easy traps

  • Writing the five fields of a cron rule (minute hour day month weekday) in the wrong order
  • Writing a cron job's command with a relative path (./backup.sh), which errors out because cron runs from a different working folder — use an absolute path (/home/user/backup.sh) instead

Now try it yourself

Run crontab -e (or crontab -l) — it might be empty. Then write out a rule line for 'run backup.sh every day at noon' yourself (no need to actually run it, just practice the syntax).

You'll know it worked when: Running crontab -l shows the schedule rules you've added.

Scheduling Tasks with Cron | Thuta Learning