# Debian Scheduling Run tasks at specific times or intervals using `cron` or `at`. ## Cron Most common scheduler. Edit user crontab: ```bash crontab -e ``` Edit root crontab: ```bash sudo crontab -e ``` List your crons: ```bash crontab -l ``` ## Cron Format ``` minute hour day month day-of-week command 0 2 * * * /path/to/backup.sh ``` Fields: - `minute` — 0-59 - `hour` — 0-23 - `day` — 1-31 - `month` — 1-12 - `day-of-week` — 0-6 (0=Sunday) Special values: - `*` — any value - `*/5` — every 5 units - `1-5` — range - `1,3,5` — specific values Examples: ```bash 0 2 * * * # 2 AM daily */30 * * * * # every 30 minutes 0 0 * * 0 # midnight Sunday (weekly) 0 0 1 * * # 1st of month (monthly) 0 0 1 1 * # 1 Jan (yearly) @reboot # on boot ``` ## Cron Permissions Allow/deny users in: ```bash sudo nano /etc/cron.allow # whitelist sudo nano /etc/cron.deny # blacklist ``` ## Checking Cron Jobs System cron jobs in: ```bash ls /etc/cron.d/ cat /etc/crontab ``` List running cron processes: ```bash ps aux | grep cron ``` View cron logs: ```bash journalctl -u cron tail -f /var/log/syslog | grep CRON ``` ## At Run once at a specific time: ```bash at 3pm tomorrow at> /path/to/command at> [Ctrl+D] ``` List scheduled jobs: ```bash atq ``` Remove job: ```bash atrm jobid ``` ## Systemd Alternative Modern approach using `systemd-run`: ```bash systemd-run --on-calendar="daily" /path/to/command ``` Or create a timer unit for complex scheduling. ## Tips - Redirect output: `0 2 * * * /backup.sh >> /var/log/backup.log 2>&1` - Use full paths in commands - Test commands manually before adding to cron - Cron runs with minimal environment; set `PATH` if needed