> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Crontab Every 5 Minutes: How to Schedule Tasks with Cron

> To run a cron job every 5 minutes, add */5 * * * * /path/to/script.sh with crontab -e. Learn the five crontab fields, examples, logging and troubleshooting.

To run a task every 5 minutes with cron, open your crontab with `crontab -e` and add the line `*/5 * * * * /home/alex/backup.sh >> /home/alex/backup.log 2>&1`. The five fields are minute, hour, day of month, month and day of week; `*/5` in the minute field means "every 5 minutes". Save and exit; cron picks up the change automatically. Check it with `crontab -l`.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 10 minutes | Ubuntu 22.04 / 24.04, Debian 12 / 13, AlmaLinux / Rocky 9 / 10 | A user account; sudo for system jobs |

## Before you start

* [Connect with SSH](https://help.freakhosting.com/portals/other/how-to-connect-to-a-linux-server-with-ssh.md).
* **cron** is a background service that runs commands on a schedule. Each user has their own list of jobs, called a **crontab**.
* Make sure cron is installed and running. Ubuntu and Debian call the service `cron`, AlmaLinux and Rocky call it `crond` (package `cronie`):

> [tab] Ubuntu / Debian
>
> ```bash theme={null}
> sudo apt install cron
> sudo systemctl enable --now cron
> ```

> [tab] AlmaLinux / Rocky
>
> ```bash theme={null}
> sudo dnf install cronie
> sudo systemctl enable --now crond
> ```

## How to add a cron job

**1. Open your crontab**

```bash theme={null}
crontab -e
```

The first time, Ubuntu and Debian may ask which editor to use. Choose `nano` if unsure.

**2. Add a line at the bottom**

```text theme={null}
*/5 * * * * /home/alex/backup.sh >> /home/alex/backup.log 2>&1
```

`>> file 2>&1` saves the output and errors to a log so you can see what happened.

**3. Save and exit**

In nano press `Ctrl+O`, `Enter`, `Ctrl+X`. You see `crontab: installing new crontab`.

**4. List your jobs**

```bash theme={null}
crontab -l
```

Make the script executable (`chmod +x /home/alex/backup.sh`) and give it a first line such as `#!/bin/bash`.

## How to read the crontab syntax

```text theme={null}
*    *    *    *    *    command
│    │    │    │    │
│    │    │    │    └── day of week (0–7, 0 and 7 = Sunday, or sun–sat)
│    │    │    └─────── month (1–12 or jan–dec)
│    │    └──────────── day of month (1–31)
│    └───────────────── hour (0–23)
└────────────────────── minute (0–59)
```

| Symbol | Meaning | Example |
| - | - | - |
| `*` | Every value | `*` in hour = every hour |
| `*/n` | Every n units | `*/15` in minute = every 15 minutes |
| `a,b` | A list | `1,15` in day = the 1st and 15th |
| `a-b` | A range | `1-5` in day of week = Monday to Friday |

## Crontab examples

| Schedule | Line |
| - | - |
| Every minute | `* * * * * /path/to/script.sh` |
| Every 5 minutes | `*/5 * * * * /path/to/script.sh` |
| Every 15 minutes | `*/15 * * * * /path/to/script.sh` |
| Every hour, on the hour | `0 * * * * /path/to/script.sh` |
| Every 6 hours | `0 */6 * * * /path/to/script.sh` |
| Every day at 03:30 | `30 3 * * * /path/to/script.sh` |
| Every day at midnight | `0 0 * * * /path/to/script.sh` |
| Weekdays at 08:00 | `0 8 * * 1-5 /path/to/script.sh` |
| Sundays at 04:00 | `0 4 * * 0 /path/to/script.sh` |
| First day of each month | `0 2 1 * * /path/to/script.sh` |
| At every boot | `@reboot /path/to/script.sh` |

Shortcuts also exist: `@hourly`, `@daily`, `@weekly`, `@monthly` and `@yearly`.

> [!NOTE]
>
> Times use the server's time zone, which is often UTC on a new server. Check it with `timedatectl` and change it with [set the time zone](https://help.freakhosting.com/portals/other/how-to-set-the-timezone-and-time-sync-on-linux.md).

## How to run a job as root (system cron)

Use root's crontab with `sudo crontab -e`, or create a file in `/etc/cron.d/`. Files there have an extra **user** field before the command:

```bash theme={null}
sudo nano /etc/cron.d/db-backup
```

```text theme={null}
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
30 2 * * * root /usr/local/bin/db-backup.sh >> /var/log/db-backup.log 2>&1
```

On Debian and Ubuntu, file names in `/etc/cron.d/` may only contain letters, digits, `-` and `_`. A name with a dot, such as `backup.cron`, is skipped. For scripts that only need "roughly daily", drop an executable script into `/etc/cron.daily/`.

## How to check it worked

**1. Wait for the next run**

For a 5-minute job, wait up to 5 minutes.

**2. Look at your log file**

```bash theme={null}
tail /home/alex/backup.log
```

**3. Check cron's own log**

> [tab] Ubuntu / Debian
>
> ```bash theme={null}
> sudo journalctl -u cron --since "1 hour ago"
> ```

> [tab] AlmaLinux / Rocky
>
> ```bash theme={null}
> sudo journalctl -u crond --since "1 hour ago"
> ```
>
> With `rsyslog` installed, cron also writes to `/var/log/cron`.

Each run appears as a `CMD (...)` line.

## Why is my cron job not running?

| Cause | Fix |
| - | - |
| Command works in the terminal but not in cron | cron uses a short `PATH`. Use full paths (`/usr/bin/php`, find them with `command -v php`) or set `PATH=` at the top of the crontab |
| `%` in the command | cron treats `%` as a new line. Escape it: `date +\%F` |
| Script isn't executable | `chmod +x script.sh` and add `#!/bin/bash` as the first line |
| Environment variables missing | cron doesn't read `~/.bashrc`. Set variables in the script or the crontab |
| Last line ignored | Make sure the crontab ends with a new line |
| Service not running | `systemctl status cron` (or `crond`) |

## Frequently asked questions

### How do I run a cron job every 30 seconds?

cron's smallest step is one minute. Use two lines, the second starting with `sleep 30;`, or use a systemd timer with `OnUnitActiveSec=30s`.

### How do I delete a cron job?

Run `crontab -e` and delete the line. `crontab -r` removes your **whole** crontab without asking, so avoid it unless you mean it.

### How do I stop cron emailing me?

Add `MAILTO=""` at the top of the crontab, or redirect output with `>> /path/to/log 2>&1`.

### How do I stop a job from running twice at once?

Wrap it in `flock`: `*/5 * * * * flock -n /tmp/backup.lock /home/alex/backup.sh`. If the previous run is still going, the new one exits.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every server guide in one place.

> [card] [Create a systemd service](https://help.freakhosting.com/portals/other/how-to-create-a-systemd-service.md)
>
> For programs that run all the time.

> [card] [Back up a Linux server](https://help.freakhosting.com/portals/other/how-to-back-up-a-linux-server.md)
>
> A job worth scheduling.

> [card] [Set the time zone](https://help.freakhosting.com/portals/other/how-to-set-the-timezone-and-time-sync-on-linux.md)
>
> Make cron run at the right hour.

> [card] [Read logs with journalctl](https://help.freakhosting.com/portals/other/how-to-read-logs-with-journalctl.md)
>
> Check that jobs ran.

***

> [!NOTE]
>
> **Checked against the official Debian [crontab(5)](https://manpages.debian.org/trixie/cron/crontab.5.en.html) and [cron(8)](https://manpages.debian.org/trixie/cron/cron.8.en.html) manuals and the [Red Hat Enterprise Linux 9 documentation](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9)** on 4 November 2026; crontab commands tested on Ubuntu 24.04 LTS. Commands can differ on other distributions or releases.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.