Skip to content
Learn Netverks

Lesson

Step 24/36 67% through track

cron-bash

Cron and scheduling

Last reviewed May 28, 2026 Content v20260528
Track mode
none
Means
Read / quiz
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Cron and scheduling: the syntax, patterns, and safety habits you need before advancing in Bash.

Teams still ship Cron and scheduling in Bash codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Cron and scheduling in contexts like: Scheduled backups, CI deploy steps, and release automation on Linux runners.

Read each lesson, copy bash examples into your own terminal, and complete the lesson MCQs—there is no in-browser runner for security reasons.

When you can explain the previous lesson's ideas without copying starter code.

cron runs commands on a schedule on Linux servers. Bash scripts are common cron targets—keep them idempotent and log output.

Crontab format

# min hour dom month dow command
0 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1

Fields: minute, hour, day-of-month, month, day-of-week. Use crontab -e for your user table.

Script hygiene for cron

#!/usr/bin/env bash
export PATH="/usr/local/bin:/usr/bin:/bin"
cd /opt/app || exit 1
./run-job.sh

Cron environments are minimal—set PATH and cd explicitly.

Alternatives

systemd timers, GitHub Actions schedules, and cloud schedulers replace cron in many stacks—Bash glue scripts stay the same pattern: exit codes and logs.

Important interview questions and answers

  1. Q: Why set PATH in cron scripts?
    A: Cron provides a sparse environment—commands may not be found otherwise.
  2. Q: Redirect cron output?
    A: Capture stdout/stderr to log files for debugging silent failures.

Self-check

  1. How many time fields does a cron line have?
  2. Why cd to the app directory first?

Tip: Log cron output somewhere visible—silent failures are hard to debug.

Interview prep

Cron fields?

minute hour day month weekday command.

Sparse cron PATH?

Set PATH explicitly in cron scripts.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Cron vs systemd?
  • MAILTO noise?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump