schedule a command with cron

Run a command every day, every hour or every few minutes, and see what is scheduled.

  • system
  • services

Steps

  1. crontab -e

    edit your schedule; a line is minute hour day month weekday command

  2. crontab -l

    show your schedule

  3. sudo crontab -u NAME -l

    another user's

  4. ls /etc/cron.d /etc/cron.daily /etc/cron.hourly

    the system's scheduled jobs

  5. systemctl list-timers

    systemd's timers, the other kind of schedule

  6. grep CRON /var/log/syslog

    check that a job ran (Debian, Ubuntu)

Notes

  • */5 * * * * /home/me/backup.sh runs 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

  • crontab
  • systemctl

Each has a page in lore: lore crontab opens it.