schedule a command with cron
Run a command every day, every hour or every few minutes, and see what is scheduled.
Steps
-
crontab -eedit your schedule; a line is minute hour day month weekday command
-
crontab -lshow your schedule
-
sudo crontab -u NAME -lanother user's
-
ls /etc/cron.d /etc/cron.daily /etc/cron.hourlythe system's scheduled jobs
-
systemctl list-timerssystemd's timers, the other kind of schedule
-
grep CRON /var/log/syslogcheck that a job ran (Debian, Ubuntu)
Notes
*/5 * * * * /home/me/backup.shruns every 5 minutes;0 3 * * * …every day at 3:00.- cron sees a new crontab by itself: no restart needed.
- cron runs with almost no PATH: write full paths, and send the output to a file to see errors.
Commands used
crontabsystemctl
Each has a page in lore: lore crontab opens it.
Related recipes
- read the system logsFind what went wrong: the errors since boot, a service's log, the kernel's messages.
- why won't a service startRead what a systemd service said when it failed, check its unit file and its configuration, then start it again.
- add a userCreate an account with a home folder and a password, and let it use sudo if it should.
- count the processorsHow many processors and cores this machine has, and what they are.