Suggested day 2720–30 minutesCaution

Mission 2 of 5

Scheduling Without Breaking Your Crontab

Design a scheduled task and test its command before touching crontab.

Learn cron syntax and safe scheduling concepts without requiring changes to your real user crontab.

Outcome: You understand scheduled tasks and know why editing crontab deserves care.

Mental model

Understand what is happening

cron runs commands on a schedule.

crontab -r removes the whole user crontab, so avoid it while learning.

A shell loop can simulate repeated work inside the sandbox.

Guided lab

Work through the mission

1

Read current crontab

Read-only

Checks that the crontab command exists before listing entries, and distinguishes a missing tool from an empty or inaccessible user crontab. Scheduling also requires a working cron-compatible service.

Terminal
if ! command -v crontab >/dev/null; then
  echo "crontab is not installed in this environment"
else
  crontab -l 2>/dev/null || echo "No user crontab exists, or access is unavailable"
fi
2

Safe scheduling simulation

Safe

Simulates repeated scheduled work without editing crontab.

Terminal
cd ~/linux-practice
mkdir -p logs
for i in {1..3}; do echo "Simulated run at $(date)" >> logs/schedule-demo.log; sleep 2; done
cat logs/schedule-demo.log
3

Dangerous cleanup example

Explanation

Removes the entire user crontab. Explanation only; do not use as course cleanup.

Terminal
crontab -r

Checkpoint

Verify the mission

The command succeeds manually before any schedule is proposed.

Try it yourself

One step without a recipe

Write out what this means: */5 * * * * command. Run the safe scheduling simulation.

Need a hint?

Write cron jobs with full paths. Cron has a minimal environment—usually not your interactive PATH or aliases. For this course, use `$HOME/linux-practice/scripts/backup.sh` while testing interactively, then put the resolved absolute path from `realpath` into a real crontab. WSL also needs a running scheduler service.

Explain it back

Before you move on

  • What does crontab -l do?
  • Why is crontab -r dangerous for beginners?

Shortcuts:Alt + ← previous lessonAlt + → next lessonAlt + H home? focus search