LAB-AUTO-01 - Cron & Scheduling
Cron & Scheduling
Practice reading cron syntax, creating one safe scheduled job, and verifying that it ran as expected.
- Practice reading cron syntax, creating one safe scheduled job, and verifying that it ran as expected.
- Repeat the workflow without copy-paste or step-by-step prompting.
- Schedule jobs against sample files or folders in your home directory until you are confident that the schedule and command behave as expected.
Part A: The Field Guide
What This Lab Is Really About
Scheduling matters because some work should happen on time, not only when you remember it.
Cron is a simple Linux scheduler. It checks a table of jobs every minute and runs any command whose time pattern matches the current minute.
In this lab, the goal is not to schedule something dramatic. The goal is to learn:
- how to read cron timing
- how to add one safe job
- how to verify that it actually ran
Mental Model: A Calendar Plus a Command
Each cron line has five time fields, followed by the command to run:
* * * * * command
From left to right, the fields mean:
- minute
- hour
- day of month
- month
- day of week
Examples:
* * * * *= every minute0 * * * *= at minute 0 of every hour30 6 * * 1= at 06:30 every Monday
Command Reference
crontab -l crontab -e crontab -r
Use these carefully:
crontab -llists your current jobscrontab -eedits your personal schedulecrontab -rremoves your personal schedule completely
For learning, stay in your own user crontab. Do not edit root jobs unless you have a specific need and understand the impact.
Why Absolute Paths Matter
Cron runs with a much smaller environment than your interactive shell. Use absolute paths for commands and files whenever possible, such as /usr/bin/date instead of just date.
Part B: The Drill Deck
Terminal required: open a Linux terminal and work in your own home directory.
G Guided Step by step - type exactly this and compare the result >
Exercise G1: Read the Current Schedule
- List your current cron jobs:
crontab -l - If cron says there is no crontab for your user, that is fine.
- Open the editor:
crontab -e - Read the help text or comments that appear, then exit without saving.
Exercise G2: Find the Paths You Need
- Find the full path to
date:which date - Print your home directory path:
echo $HOME - We will use both values in the scheduled command.
Exercise G3: Add One Safe Job
- Open your crontab again:
crontab -e - Add this line at the bottom, replacing the
datepath only if your system showed a different one:
* * * * * /usr/bin/date >> $HOME/cron-practice.log- Save and close the editor.
- Confirm the job is installed:
crontab -l
S Solo Task described, hints available - figure it out >
Exercise S1: Verify the Job Actually Ran
- Wait a little over one minute.
- Read the log file:
cat "$HOME/cron-practice.log" - Wait another minute and read it again.
- Confirm that a new timestamp line was appended.
Exercise S2: Remove the Job Cleanly
- Open the editor:
crontab -e - Delete the line you added.
- Save and close.
- Run
crontab -lagain and verify the job is gone.
M Mission Real scenario - no hints, combine multiple skills >
Mission M1: Translate the Schedule
Translate each cron expression into plain English:
0 12 * * * /opt/report.sh15 2 * * 1 /opt/cleanup.sh*/10 * * * * /opt/check.sh
Your answer should describe:
- the minute
- the hour if relevant
- whether it runs every day or on specific days