Scheduling Tasks - Paiet/Tech-Journal-for-Everything GitHub Wiki

  • cron
    • Designed for repeating tasks
    • Suitable for services and end users
  • at
    • Designed for one-off tasks
    • Suitable for end users
  • at
    • at 3 PM Fri
      • Enter commands
      • Ctrl-D to end
    • atq (Lists queued commands)
    • atrm <#> removes a job
  • Securing at
    • /etc/at.allow
    • /etc/at.deny
    • If neither exist, only root can run the at command
  • cron
    • Executes jobs at a predetermined time
    • User cron jobs (varies by distro)
      • /var/spool/cron/username
      • /var/spool/cron/tabs/username
      • /var/spool/cron/crontabs/username
    • System cron jobs
      • /etc/cron.d/
      • /etc/cron.hourly/
      • /etc/cron.daily/
      • /etc/cron.weekly/
      • /etc/cron.monthly/
    • Example
      • /etc/cron.daily/logrotate
  • Creating cron jobs
    • Job syntax
      1. Minute of the hour (0-59)
      2. Hour of the day (0-23)
      3. Day of the month (1-31)
      4. Month of the year (1-12)
      5. Day of the week (0-7)
      6. User context for execution
      7. Command and options
    • Create jobs at a specific time
      • /etc/crontab (System)
      • crontab -e (User)
        • Run a backup every night at 3AM e.g. 0 3 * * * /home/dpezet/backupdb.sh
      • e.g crontab -l -u <user>
        • Lists a user's cron jobs
  • Restrict access to cron
    • /etc/cron.allow
    • /etc/cron.deny
    • Use one or the other
    • List usernames one per line
  • anacron
    • Similar to cron
    • Designed for desktops/laptops
    • Will run jobs that were scheduled to run while system was offline.
    • /etc/anacrontab
⚠️ **GitHub.com Fallback** ⚠️