How to Add a Cron Job

Cron is a UNIX utility that execute programs at regular intervals. Each user and root can specify his own set of commands by creating his own crontab file.

Things You'll Need

  • Linux or Unix
Show More

Instructions

    • 1

      Create a script or determine which command you want to be executed regularly and determine how often it should be run.
      For the purposes of this example, a fictional script named "backup.sh" is contained in Mary's home directory. It will run every Friday at midnight.

    • 2

      Open a terminal window. Terminal windows are found under Utilities in the Start Menu.

    • 3

      Start the crontab editor with the command:
      crontab -e

    • 4

      Enter your cron job in the form:
      Minutes Hours DayofMonth Month DayofWeek command.
      Any field not applicable to your job should have an asterisk (*) as a place holder. If you want to specify more than 1 value for any field, separate the values with a comma and no white space. The days of the week are indicated by a number with Sunday being 0.
      For example:
      0 0 * * 5 /home/Mary/backup.sh
      To run on Mondays, Wednesdays and Fridays, the entry would be:
      0 0 * * 1,3,5 /home/Mary/backup.sh

    • 5

      Save your entry and quit the editor. Cron will automatically read the file and schedule the job.

    • 6

      To make sure your entry has been issued, type the command:
      crontab -l

Tips & Warnings

  • This example will add a job for 1 user. If you want to add a system-wide job, you must log in as root, or place "sudo" in front of each command.

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured