Understanding cron.daily Execution: Configuration and Timing in Linux Systems


3 views

In Linux systems managed by cron or anacron, the /etc/cron.daily/, /etc/cron.weekly/, and /etc/cron.hourly/ directories contain scripts that run at specific intervals. The exact execution time depends on your system configuration:

  • On systems using Vixie cron (common in RHEL/CentOS), these run via /etc/crontab entries
  • On systems using anacron (common in Ubuntu/Debian), timing is more flexible

For traditional cron implementations (RHEL5/CentOS4 as mentioned):

# Typical crontab entry in /etc/crontab
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

This means:

  • cron.daily runs at 4:02 AM every day
  • cron.weekly runs at 4:22 AM every Sunday
  • cron.monthly runs at 4:42 AM on the 1st of each month

You can modify these timings by:

1. Editing /etc/crontab directly:

# Change daily cron to run at 3 AM instead
02 3 * * * root run-parts /etc/cron.daily

2. Using anacron (if available):

Edit /etc/anacrontab:

# Format: period delay job-identifier command
1       5       cron.daily      nice run-parts /etc/cron.daily
7       10      cron.weekly     nice run-parts /etc/cron.weekly
@monthly        15      cron.monthly    nice run-parts /etc/cron.monthly

To verify how your system is configured:

# For traditional cron
cat /etc/crontab | grep cron.[daily|weekly|monthly]

# For anacron systems
cat /etc/anacrontab

Create a script in /etc/cron.daily/:

#!/bin/bash
# /etc/cron.daily/my-backup
logger "Starting daily backup routine"
/path/to/backup-script.sh

Make it executable:

chmod +x /etc/cron.daily/my-backup
  • Check /var/log/cron for execution logs
  • Ensure scripts in cron.* directories have execute permissions
  • Verify your system uses cron or anacron (ps aux | grep -E 'cron|anacron')

On most Linux distributions including RHEL and CentOS, the cron.daily, cron.weekly, and cron.hourly jobs are triggered by anacron or cron itself. The default schedule is:

# Default times in /etc/crontab or /etc/anacrontab
0 0 * * * root run-parts /etc/cron.daily
0 0 * * 0 root run-parts /etc/cron.weekly
0 * * * * root run-parts /etc/cron.hourly

The exact timing depends on your system configuration. Check these files:

# For systems using cron
/etc/crontab

# For systems using anacron (common on desktop/laptops)
/etc/anacrontab

Here's a typical /etc/anacrontab configuration:

# /etc/anacrontab
# period in days   delay in minutes   job-identifier   command
1       5       cron.daily      run-parts /etc/cron.daily
7       10      cron.weekly     run-parts /etc/cron.weekly
@monthly        15      cron.monthly    run-parts /etc/cron.monthly

To modify when these jobs run:

  1. For cron-based systems: Edit /etc/crontab
  2. For anacron systems: Edit /etc/anacrontab

Example: To run daily jobs at 3 AM instead:

# In /etc/crontab
0 3 * * * root run-parts /etc/cron.daily

Check when jobs last ran:

ls -lt /var/spool/anacron

Or for cron:

grep cron /var/log/cron
  • On servers, cron is typically used
  • On workstations/laptops, anacron is common (handles missed jobs)
  • Some distros use systemd timers instead

1. Create your script in /etc/cron.hourly:

#!/bin/bash
# /etc/cron.hourly/myscript
echo "Hourly job ran at $(date)" >> /var/log/mycron.log

2. Make it executable:

chmod +x /etc/cron.hourly/myscript