If you need a certain Linux script, command, or program to regularly run at a certain time, you can schedule the event (called a "job") using cron. We'll show you how to open your cron configuration file and schedule your first cron job.

Method 1
Method 1 of 2:

Setting up the File

  1. 1
    Using your favourite editor, create a cron file with a line for each job you wish to schedule, in the format: m h d m w command
    • m minute
    • h hour
    • d day of month
    • m month 1-12
    • w weekday 0-7, Sun,Mon, etc (Sunday = 0 = 7) It is easy to remember if you think of the way one would say a date: Wednesday, July 29, at 10:30, then reverse the order.
  2. 2
    Load your file into crontab: crontab yourfile
  3. Advertisement
Method 2
Method 2 of 2:

Trying an Example

  1. 1
    Create a file testCron.txt containing the following lines:
    • # do this every 10 minutes
    • */10 * * * * date >> ~/testCron.log
  2. 2
    Load it into cron: crontab testCron.txt
  3. 3
    Wait 30 minutes, check testCron.log, if it works it will update your file with a time stamp 3 times.
  4. 4
    Remove the crontab so that it does not run forever: crontab -r
  5. Advertisement

About This Article

wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 10 people, some anonymous, worked to edit and improve it over time. This article has been viewed 112,584 times.
How helpful is this?
Co-authors: 10
Updated: December 17, 2021
Views: 112,584
Categories: Linux
Advertisement