Configure system-wide recurring tasks using the correct cron interval directories and enforce executable permissions. Validate placement by enumerating the cron directories and confirming each script’s purpose and run frequency.
Your team needs you to configure system-wide recurring tasks that run at predictable intervals. You must place scripts in the correct cron interval directories so the system scheduler runs them automatically, and you must ensure scripts are executable so they actually fire.
This is baseline automation work. Correct placement and executable permissions are what separate a working schedule from a silent failure.
/etc/cron.hourly,
/etc/cron.daily,
/etc/cron.weekly,
and /etc/cron.monthly.
ls /etc/cron.*
These directories represent fixed scheduling intervals. Scripts placed here are executed automatically at the corresponding cadence.
/etc/cron.daily/
/etc/cron.hourly/
/etc/cron.monthly/
/etc/cron.weekly/
sudo vim /etc/cron.hourly/cleanup_logs
#!/bin/bash
find /var/log -type f -name '*.log' -mtime +3 -delete
sudo chmod +x /etc/cron.hourly/cleanup_logs
sudo vim /etc/cron.daily/backup_home
#!/bin/bash
tar -czf /backup/home_$(date +%F).tar.gz /home
sudo chmod +x /etc/cron.daily/backup_home
sudo vim /etc/cron.monthly/monthly_sync
#!/bin/bash
rsync -av /backup/ /mnt/nas/monthly_archive
sudo chmod +x /etc/cron.monthly/monthly_sync
Most interval directories require executable scripts. Check
permissions with ls -l and confirm the
executable bit is set.
Cron runs with a minimal environment. Use absolute paths and avoid relying on shell profiles or relative directories.
Confirm the script is in the correct directory. A script in
/etc/cron.monthly will not run hourly or daily.
Remove the test scripts to return the system to its original state.
sudo rm -f /etc/cron.hourly/cleanup_logs
sudo rm -f /etc/cron.daily/backup_home
sudo rm -f /etc/cron.monthly/monthly_sync
ls /etc/cron.*
: Lists system-wide cron interval directories and their
contents.
sudo vim /etc/cron.hourly/cleanup_logs
: Creates or edits an hourly cron script.
sudo vim /etc/cron.daily/backup_home
: Creates or edits a daily cron script.
sudo vim /etc/cron.monthly/monthly_sync
: Creates or edits a monthly cron script.
sudo chmod +x <script>
: Makes a cron script executable.
+x: adds execute permission.find /var/log -type f -name '*.log' -mtime +3 -delete
: Removes log files older than three days.
-type f: match files only.-name '*.log': match log filename pattern.-mtime +3: older than 3 days.-delete: remove matched files.tar -czf <archive> /home
: Creates a compressed archive of the home directory.
-c: create archive.-z: gzip compress.-f: write to file.rsync -av /backup/ /mnt/nas/monthly_archive
: Synchronizes backup data to a remote archive location.
-a: archive mode.-v: verbose output.