Manage scheduled tasks with cron
Schedule automatic execution of scripts, backups and maintenance tasks.
What this tutorial does
The tutorial "Manage scheduled tasks with cron" helps you achieve this goal:
Schedule automatic execution of scripts, backups and maintenance tasks.
Debian/Ubuntu
-
--- edit crontab of current user --- -
crontab -e - --- Syntax: minute hour day month day_week command ---
- Every minute: * * * * * /chemin/script.sh
- Every day at 2 a.m.: 0 2 * * * /chemin/script.sh
- Every Monday at 8 a.m.: 0 8 * * 1 /chemin/script.sh
- The 1st of the month at midnight: 0 0 1 * * /path/script.sh
- Every 5 minutes: */5 * * * * /chemin/script.sh
- --- Best practices ---
- Always use absolute paths in scripts.
- Redirect output to a log: command >> /var/log/tache.log 2>&1
- Test the script manually before scheduling it.
-
--- System Crontab (all apps) --- -
Edit /etc/crontab or create a file in /etc/cron.d/ - Format: minute hour day month dow user command
- --- View active crontabs ---
-
crontab -l (current user) -
cat /etc/crontab (system) - --- Check execution logs ---
-
grep CRON /var/log/syslog | tail -20