FLOPPIX Home | FAQ | Download | Labs | ToC | Back |  Next 

Scheduling tasks with cron


Notes:

  1. Cron is used to automate periodic tasks (eg: backup the hard drive at every Sunday at 3 a.m. or email yourself a reminder about the Linux Users Group meeting the first day of every month)
     

  2. Users setup the configuration file for cron using the command: crontab

  3. Your configuration file is stored in the directory: /var/spool/crontabs under your username.
     
  4. The crond daemon checks the crontab files every minute to determine if  a task should be launched in that minute.
     
  5. Each line in a crontab file has 6 fields:
  6. If the command produces output, the output will be sent to you in an email message.
     
  7. Example 1:
    19   20   *   *   Sun   echo Study Linux
    Every Sunday, at 20:19, echo Study Linux (you will receive this as an email message)
     
  8. Example 2:
    13,18,23,28   5   *   *   Mon-Fri   /usr/bin/who
    Monday to Friday, at 5:13, 5:18, 5:23 and 5:28 execute /usr/bin/who
     
  9. Example 3:
    43   */2   1   *   *   echo Pay Bills
    On the first day of every month, every 2 hours at 43 minutes past the hour, echo Pay Bills.


Exercises:

  1. Setup a cron job to echo Study Linux every 30 minutes, Monday to Friday.
     
  2. Setup a cron job to echo Study Linux every hour on Saturday and Sunday.
     
  3. Setup a script that displays the date and then a list of everyone who is logged on. Run your script and make sure that it works. Setup cron to run the script you created on the first day of every month at 08:02.
  4. Setup a script called backup that echoes the message "You should backup now". Run your script and make sure that it works. Setup cron to run the script you created in question two the first day of every month at 07:17.
  5. When you are sure that this is working correctly, store the output from crontab -l in the file cronlist.
     
  6. Run crontab -r to delete all of your cron tasks.

Copyright © L.M.MacEwan
FLOPPIX Home | FAQ | Download | Labs | ToC | Back |  Next