In most Linux distributions using systemd, the cron.daily
jobs are actually triggered by a systemd timer rather than traditional cron. The default execution time is typically set in:
/etc/systemd/timers.target.wants/timers.target
First, let's verify how your system currently schedules daily jobs:
systemctl list-timers --all
# Or for more detailed info:
systemctl cat cron-daily.timer
There are two primary methods to change the execution time:
Method 1: Editing systemd Timer
Create an override file to change the schedule:
sudo systemctl edit cron-daily.timer
# Add these lines (example for 3:30 AM):
[Timer]
OnCalendar=*-*-* 03:30:00
RandomizedDelaySec=30m
Method 2: Using Anacron (for non-systemd systems)
Edit the anacrontab file:
sudo nano /etc/anacrontab
# Modify the START_HOURS_RANGE line:
START_HOURS_RANGE=3-4
After making changes, reload systemd and check the new schedule:
sudo systemctl daemon-reload
sudo systemctl restart cron-daily.timer
systemctl list-timers | grep daily
For more precise control, consider moving the script to root's crontab:
sudo crontab -e
# Add this line for daily execution at 4:15 AM:
15 4 * * * /etc/cron.daily/your_script
Ensure your system time zone is correctly set as cron jobs use the system timezone:
timedatectl
# If needed, set timezone:
sudo timedatectl set-timezone America/New_York
If your changes don't take effect, check logs:
journalctl -u cron-daily.timer
journalctl -u cron-daily.service
In Linux systems, scheduled jobs in /etc/cron.daily/
are executed by anacron
(on desktop systems) or cron
(on servers) through the /etc/crontab
configuration. The default execution time is typically early morning (usually around 6:25 AM on most distributions).
The execution time is controlled by one of these files depending on your system:
/etc/crontab /etc/anacrontab /etc/cron.d/0hourly
For cron-based systems (common on servers):
# Edit /etc/crontab sudo nano /etc/crontab # Find the line similar to: 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) # Change the time (format: minute hour) 30 4 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
For anacron-based systems (common on desktops):
# Edit /etc/anacrontab sudo nano /etc/anacrontab # Look for the daily jobs section: 1 5 cron.daily run-parts --report /etc/cron.daily # The second field (5) represents the delay in minutes after system start
For more precise control, consider moving your script to a direct crontab entry:
# Edit root's crontab sudo crontab -e # Add a line like this (runs at 3:15 AM daily): 15 3 * * * /path/to/your/script.sh
After making changes, check the logs to verify execution:
# Check cron logs grep cron /var/log/syslog # Or for systems with journalctl: journalctl -u cron.service --since today
Remember that cron jobs use the system timezone. To check and modify:
# View current timezone timedatectl # List available timezones timedatectl list-timezones # Change timezone sudo timedatectl set-timezone America/New_York