# Schedule Scripts Using Crontab

Many Unix systems come preinstalled with `crontab`, a tool that generates a file where each row is a *cron job*, or a program/script set to run at a specific time or interval.

Creating cron jobs is useful for periodically running programs. For example, you could create a script that searches your directory for files older than 1 year, and then create a cron job that runs this script once a month.

To specify the schedule for which a cron job should run, you need to use cron schedule expression. Cron schedule expressions have the following format:

```
  *        *              *                 *              *
(min)    (hour)    (day of the month)    (month)    (day of the week)
```

The first place represents the minute that the cron job should run at. The second place the hour, the third place the day of the month, the fourth the month, the fifth the day of the week.

A `*` indicates to run at "any" time. So a `*` over the month position would mean run on any month.

Prepending a number with `*/` means "every" . So a `*/5` over the minute position would mean run every 5th minute, A.K.A. every 5 minutes.&#x20;

The following expression would dictate that the cron job run at 6:00 AM everyday, A.K.A. the 0th minute of the 6th hour on any day of the month, any month, and any day of the week.

```
0 6 * * *
```

The following expression would dictate that the cron job run every 30 minutes on Saturday, A.K.A. every 30th minute of any hour on any day of the month, any month, and on the 6th day of the week.

```
*/30 * * * 6
```

It's easy to get confused making cron schedule expressions, so I recommend using a site such as <https://crontab.guru/> that makes it easy to construct the expressions and describe them to you.

Once you have a cron schedule expression, you can create a cron job in your crontab using the command `crontab -e`, which will open an editor for you the add your cron job. Put your cron job on an empty line with the following format:

```bash
0 6 * * * /home/asoberan/your/script.sh
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://igb.mit.edu/mini-courses/introduction-to-unix/schedule-scripts-using-crontab.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
