How Debian Structures /etc/cron.* Schedules
This article provides an overview of how Debian manages periodic
background tasks using predefined /etc/cron.* directories.
Debian organizes these automated jobs by execution frequency rather than
requiring individual user crontab entries, relying on the system-wide
/etc/crontab file and the run-parts utility to
execute maintenance tasks, system updates, and custom scripts
reliably.
The Role of
/etc/crontab and run-parts
At the center of Debian's automated scheduling is the master
/etc/crontab file. Unlike user-specific crontab files
created with crontab -e, /etc/crontab
specifies an explicit user under which each job runs (typically
root) and uses the run-parts utility to
trigger all executable files located within designated interval
directories.
Debian defines these intervals by default:
/etc/cron.hourly/: Runs scripts at the 17th minute of every hour./etc/cron.daily/: Runs scripts once a day, typically at 06:25 AM./etc/cron.weekly/: Runs scripts once a week, by default on Sunday morning at 06:47 AM./etc/cron.monthly/: Runs scripts once a month on the first day of the month at 06:52 AM.
File Requirements for Periodic Directories
When placing scripts inside /etc/cron.hourly,
/etc/cron.daily, /etc/cron.weekly, or
/etc/cron.monthly, specific rules dictate how they are
processed:
- Executability: Files must have executable
permissions set (
chmod +x /path/to/script). - Interpreter Directives: Scripts must include a
proper shebang line (such as
#!/bin/shor#!/bin/bash) at the top of the file. - Strict Naming Conventions: By default,
run-partsenforces strict filename limits. Filenames must consist entirely of ASCII upper- and lower-case letters, ASCII digits, ASCII underscores, and ASCII minus-hyphens. They must not contain periods or file extensions (e.g., usebackup-database, notbackup-database.sh). If a script contains an invalid character or extension,run-partssilently ignores it.
The /etc/cron.d/
Directory
The /etc/cron.d/ directory operates differently from the
interval-based directories. Instead of containing executable scripts run
by run-parts, it stores modular crontab configuration
snippets.
Software packages and administrators use /etc/cron.d/ to
manage schedules independently without modifying
/etc/crontab directly. Files inside
/etc/cron.d/:
- Follow standard crontab syntax with the addition of a user field:
minute hour dom month dow user command. - Can specify any execution frequency rather than being locked to hourly, daily, weekly, or monthly intervals.
- Do not need to be marked as executable.
- Must strictly follow the same Debian naming conventions as
run-parts(no file extensions, no periods).
Anacron Integration
On Debian installations (especially workstations and laptops that are
not running continuously), anacron often complements or
supersedes the standard cron daemon for daily, weekly, and
monthly jobs. Defined in /etc/anacrontab, Anacron ensures
that if a system is powered off when a daily, weekly, or monthly job is
scheduled, the missed scripts inside /etc/cron.daily/,
/etc/cron.weekly/, and /etc/cron.monthly/ are
executed shortly after the system boots back up.