wEEK 13

Time Management and Task Scheduling

This week focuses on how Linux automates repetitive tasks through cron, the built-in job scheduler. Cron allows the system to run commands at precise times—every minute, every night, every Monday, or on any recurring pattern you define.

Most background maintenance on a Linux system—log rotation, backups, system updates—runs through cron. Understanding it gives you control over when and how your system works without you manually intervening.

We follow the four-step C-R-O-N framework:

C — Create Cron Jobs

A cron job is an entry in a schedule list called crontab. Each user (including root) can maintain their own crontab file.

Cron jobs run in the background, so they must be written clearly and tested carefully.

CommandPurposeDescription
crontab -lList current cron jobsShows all jobs scheduled by the current user.
crontab -eEdit jobsOpens your crontab in a text editor. Add/change scheduled tasks here.
crontab -rRemove all jobsDeletes the current user’s entire cron schedule. Use carefully.
 

A cron entry uses the format:

* * * * * command-to-run
| | | | |
| | | | └── Day of week (0–6, Sunday=0)
| | | └──── Month (1–12)
| | └────── Day of month (1–31)
| └──────── Hour (0–23)
└────────── Minute (0–59)

Example: Run a script every day at 2:30 AM: 30 2 * * * /home/user/backup.sh

 
 

R — Recurring Patterns

Cron excels at repetition. You can choose patterns that define exactly how often a job runs.

PatternExampleMeaning
* * * * *Every minuteRun constantly—use sparingly.
*/5 * * * *Every 5 minutesSpaced recurring jobs.
0 * * * *At minute 0, every hourHourly tasks.
0 3 * * 13 AM every MondayWeekly scheduled jobs.
@dailyMidnight dailyNamed shortcut schedules.
@rebootOn startupRuns once at boot time.

Example: Run a Python script every 15 minutes: */15 * * * * /usr/bin/python3 /home/user/collect_metrics.py

Recurring schedules let the system work for you—automatically.



O — Observe Schedules

You should verify that cron is running and that your jobs are recognized.

CommandPurposeDescription
systemctl status cronCheck cron serviceConfirms that the scheduler is active.
grep CRON /var/log/syslogView cron runtime logsShows when jobs run and whether they succeeded.
tail -f /var/log/syslogWatch events liveUseful for debugging while a job executes.

Cron does not display errors directly to your terminal. Logs are essential for understanding what the job actually did.



Navigate the tree​

N — Note Results

Always record outcomes—especially for backups, processing tasks, and data maintenance.

CommandPurposeDescription
echo "log info" >> ~/cron.logStore outputAppend messages to a personal log file.
command >> output.log 2>&1Log both output and errorsEnsures you capture everything.
mail (if configured)Receive cron output emailsCron can email job results automatically.

Example cron entry that logs results: 0 1 * * * /usr/local/bin/rotate_data.sh >> /home/user/cron.log 2>&1

Without logging, cron may run quietly and fail quietly. Always leave a trail.

 
 
 

This concludes Lecture 13 on Time Management and Task Scheduling. Please return to Blackboard to access the Week 13 materials.

Scroll to Top