---
tags:
- linux
- l1
- flashcard-deck
- cron
---
<!-- wiki:breadcrumb:start -->
[Portal](../../../../library/portal/index.md) | **Level:** [L1: Foundations](../../../../library/portal/levels.md) | **Topics:** [Cron & Job Scheduling](../../../../library/portal/topics.md) | **Domain:** Linux
<!-- wiki:breadcrumb:end -->

id	category	difficulty	tags	question	answer	source_path
cron/a1b2c3d4e5f6	cron	easy	cron, syntax, fields	What are the five fields in a cron schedule expression, and what values does each accept?	minute (0-59), hour (0-23), day of month (1-31), month (1-12 or JAN-DEC), day of week (0-7 or SUN-SAT, where 0 and 7 both mean Sunday). Example: 30 2 * * * runs at 2:30 AM daily. Use */N for intervals (e.g., */5 for every 5 minutes).\n\nRemember: five fields: minute (0-59) hour (0-23) day-of-month (1-31) month (1-12) day-of-week (0-7). Mnemonic: 'Must Have Delicious Meals Daily.'\n\nExample: 0 2 * * 1 = 'at 2:00 AM every Monday.' */15 * * * * = 'every 15 minutes.' 0 0 1 * * = 'midnight on the 1st of every month.'	training/library/topics/cron-scheduling/primer.md
cron/b2c3d4e5f6a7	cron	easy	cron, crontab, management	How do you list, edit, and remove a user's crontab?	crontab -l to list, crontab -e to edit, crontab -r to remove (dangerous, no confirmation). Use crontab -ri for removal with confirmation. To edit another user's crontab as root: crontab -e -u <username>. User crontabs are stored in /var/spool/cron/ (RHEL) or /var/spool/cron/crontabs/ (Debian).\n\nRemember: crontab -e (edit), crontab -l (list), crontab -r (remove ALL — dangerous!). Use crontab -l > backup.txt before editing.\n\nGotcha: cron jobs run with a minimal environment. Set PATH explicitly or use full paths to commands. Missing PATH is the #1 cron debugging issue.	training/library/topics/cron-scheduling/primer.md
cron/c3d4e5f6a7b8	cron	easy	cron, special-strings, shortcuts	What cron special strings can you use instead of five-field schedule expressions?	@reboot (run once at startup), @hourly (0 * * * *), @daily (0 0 * * *), @weekly (0 0 * * 0), @monthly (0 0 1 * *), @yearly (0 0 1 1 *). These are shorthand aliases for common schedules and improve readability.\n\nRemember: five fields: minute (0-59) hour (0-23) day-of-month (1-31) month (1-12) day-of-week (0-7). Mnemonic: 'Must Have Delicious Meals Daily.'\n\nExample: 0 2 * * 1 = 'at 2:00 AM every Monday.' */15 * * * * = 'every 15 minutes.' 0 0 1 * * = 'midnight on the 1st of every month.'	training/library/topics/cron-scheduling/primer.md
cron/d4e5f6a7b8c9	cron	medium	cron, environment, debugging	Why do cron jobs fail with "command not found" when they work in a normal shell, and how do you fix it?	Cron runs with a minimal environment: PATH=/usr/bin:/bin, SHELL=/bin/sh, and no .bashrc/.profile loaded. Fix by: \n1) using absolute paths in commands, \n2) setting PATH at the top of the crontab, \n3) sourcing the user's profile in the command, or \n4) using a wrapper script that sets up the environment. This is the number-one cron debugging issue.	training/library/topics/cron-scheduling/primer.md
cron/e5f6a7b8c9d0	cron	medium	cron, cron.d, system-crontab	What is the difference between a user crontab and a system crontab in /etc/cron.d/?	User crontabs (crontab -e) have 5 fields + command and run as the editing user. System crontabs (/etc/cron.d/) have 5 fields + a user field + command (6th field specifies which user runs the job). System crontabs can set environment variables at the top and are preferred for config-managed deployments (Ansible, etc.).\n\nRemember: comparison questions are best answered with a structured format: name the key dimensions (use case, performance, complexity, cost) and compare each.	training/library/topics/cron-scheduling/primer.md
cron/f6a7b8c9d0e1	cron	medium	cron, flock, overlap	How do you prevent a cron job from running multiple overlapping instances?	Use flock: */5 \n* * \n* * root flock -n /var/lock/job.lock /usr/local/bin/job.sh. The -n flag makes it non-blocking (exit immediately if lock exists). The -w 60 flag waits up to 60 seconds. This prevents the most common cron disaster: a job that runs longer than its interval causing overlapping instances and corrupted data.	training/library/topics/cron-scheduling/primer.md
cron/a7b8c9d0e1f2	cron	medium	cron, systemd-timers, comparison	What advantages do systemd timers have over traditional cron?	Structured logging via journald (vs mail or redirect), dependency management (After=, Requires=), resource limits (CPUQuota=, MemoryMax=), missed-run recovery (Persistent=true), random delay to spread load (RandomizedDelaySec=), built-in overlap prevention (oneshot type), calendar expression validation (systemd-analyze calendar), and unified status checking (systemctl status).\n\nRemember: systemd timers are the modern alternative to cron. Benefits: dependency management, better logging (journalctl), calendar events, and persistent timers that run after missed schedules.	training/library/topics/cron-scheduling/primer.md
cron/b8c9d0e1f2a3	cron	medium	cron, output, logging	How should you handle output and logging for cron jobs?	Redirect stdout and stderr to a log file: command >> /var/log/job.log 2>&1. Set MAILTO=ops@example.com to email any unredirected output. Suppressing all output (> /dev/null 2>&1) should be used sparingly as it hides errors. For systemd timers, logs go to journald automatically (journalctl -u service.service).\n\nRemember: cron sends output via email by default. Redirect: */5 * * * * /script.sh >> /var/log/myscript.log 2>&1. Set MAILTO='' to disable email.	training/library/topics/cron-scheduling/primer.md
cron/c9d0e1f2a3b4	cron	hard	cron, systemd-timers, oncalendar	How do you create a systemd timer that runs a backup daily at 2:30 AM with missed-run recovery?	Create two files: a timer (/etc/systemd/system/backup.timer) with [Timer] OnCalendar=*-*-* 02:30:00, Persistent=true (runs on boot if missed), RandomizedDelaySec=300. And a service (/etc/systemd/system/backup.service) with Type=oneshot, ExecStart=/usr/local/bin/backup.sh. Enable with systemctl enable --now backup.timer. Validate with systemd-analyze calendar "*-*-* 02:30:00".\n\nRemember: systemd timers are the modern alternative to cron. Benefits: dependency management, better logging (journalctl), calendar events, and persistent timers that run after missed schedules.	training/library/topics/cron-scheduling/primer.md
cron/d0e1f2a3b4c5	cron	hard	cron, gotchas, day-of-month-week	What happens when you specify both day-of-month and day-of-week in a cron expression?	In standard cron, specifying both creates an OR condition, not AND. For example, "0 0 15 \n* 1" runs at midnight on the 15th of every month OR every Monday, not only on Mondays that fall on the 15th. This is a common gotcha that leads to jobs running more often than expected. Systemd timers use AND logic instead.	training/library/topics/cron-scheduling/primer.md
cron/e1f2a3b4c5d6	cron	hard	cron, kubernetes-cronjobs, concurrency	How does a Kubernetes CronJob handle missed runs and overlapping instances?	startingDeadlineSeconds controls how late a missed job can start (without it, missed runs are silently skipped). concurrencyPolicy controls overlap: Forbid (skip if previous running), Replace (kill running and start new), Allow (default, multiple can run). For data-integrity jobs, always use Forbid. Set activeDeadlineSeconds to kill jobs that run too long, and backoffLimit to control retries.	training/library/topics/cron-scheduling/primer.md

<!-- wiki:related:start -->
---

## Wiki Navigation

### Related Content

- [Cron & Job Scheduling](../../../../library/topics/cron-scheduling/index.md) (Topic Pack, L1) — Cron & Job Scheduling

<!-- wiki:related:end -->
