Cron, at, and anacron — Bird's Linux Private Kitchen notes

Contents

  1. 1. Job scheduling
    1. 1.1. at
    2. 1.2. batch
    3. 1.3. crontab
    4. 1.4. anacron

Notes from Bird’s Linux Private Kitchen (3rd edition), kept for quick review.

Job scheduling

at

  • start service: /etc/init.d/atd restart; chkconfig atd on
  • -m # email when job completes
  • -l # same as atq; list this user’s jobs
  • -d num # same as atrm; cancel job
  • -v # show schedule in time format
  • -c num # show job contents

batch

  • runs when load average is below 0.8
  • HH:MM YYYY-MM-DD # run at specific time

crontab

  • -u uname # root only

  • -e # edit crontab

  • -l # list

  • -r # remove all entries

  • fields are tab-separated

      # Example of job definition:
      # .---------------- minute (0 - 59)
      # |  .------------- hour (0 - 23)
      # |  |  .---------- day of month (1 - 31)
      # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
      # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) 
      # |  |  |  |  |            OR sun,mon,tue,wed,thu,fri,sat
      # *  *  *  *  * user-name command to be executed
    
    special meaning
    * any value
    , list; 3,6 = 3:00 and 6:00
    - range; 3-6
    /n every n units; */5 every 5 minutes
  • /etc/crontab # system-wide schedule

      /etc/init.d/crond restart # reload after edits
    

anacron

  • runs jobs missed while the machine was off; checks timestamps under /var/spool/anacron
  • -s cron.daily # run overdue daily jobs
  • -f job # force run, ignore timestamp
  • -n job # run now, no delay
  • -u job # update timestamp only, run nothing
Questions? Leave a comment below or email: newbvirgil@gmail.com