Script Valley
Linux & Bash for Developers
Advanced Bash & AutomationLesson 6.3

Cron jobs: how to schedule tasks in Linux

crontab syntax, minute hour dom month dow fields, crontab -e, system cron vs user cron, /etc/cron.d, CRON_TZ, common schedule examples, cron logging

cron Runs Commands on a Schedule

cron is the Linux task scheduler. A crontab file contains jobs — each line specifies when and what to run. The syntax has five time fields followed by the command. It is the standard way to run backups, health checks, cleanup scripts, and any recurring task.

Crontab Syntax

# Edit your user's crontab
crontab -e

# List current crontab
crontab -l

# Field order: minute hour day-of-month month day-of-week
# Each field: number, */n (every n), range (1-5), list (1,3,5), or * (any)

# Run backup.sh every day at 2:30 AM
30 2 * * * /home/alice/scripts/backup.sh

# Run every 15 minutes
*/15 * * * * /scripts/health_check.sh

# Run at 9 AM on weekdays only (Mon=1, Fri=5)
0 9 * * 1-5 /scripts/standup_reminder.sh

# Run at midnight on the 1st of each month
0 0 1 * * /scripts/monthly_report.sh

Capture Cron Output

# By default cron emails output — redirect to log instead
30 2 * * * /scripts/backup.sh >> /var/log/backup.log 2>&1

# Use MAILTO='' to silence email
MAILTO=""
30 2 * * * /scripts/backup.sh >> /var/log/backup.log 2>&1

# Always use absolute paths in cron — PATH may differ
0 * * * * /usr/bin/python3 /home/alice/scripts/monitor.py

Up next

Environment variables and .env files in Linux

Sign in to track progress