# How to run cron jobs every 5, 10, or 30 seconds?

By default, cron checks crontabs for cronjobs every minute. If you want to run a
job every n seconds you need to use a simple workaround.

[info]
## 🔭 Want to get alerted when your Cron doesn’t run correctly?
Go to [Better Stack](https://betterstack.com/uptime/) and start monitoring in 5 minutes.
[/info]

### Specify multiple jobs with offsets

The easiest way to run a job every n seconds is to run a job every minute and,
and sleep in a loop in n second intervals.

### Every 5 seconds

```bash
[label script.sh]
i=0

while [ $i -lt 12 ]; do # 12 five-second intervals in 1 minute
  command/to/run & #run your command
  sleep 5
  i=$(( i + 1 ))
done
```

```bash
[label /etc/crontab]
* * * * * script.sh
```

### Every 10 seconds

```bash
[label script.sh]
i=0

while [ $i -lt 6 ]; do # 6 ten-second intervals in 1 minute
  command/to/run & #run your command
  sleep 10
  i=$(( i + 1 ))
done
```

```bash
[label /etc/crontab]
* * * * * script.sh
```

### Every 15 seconds

```bash
[label script.sh]
i=0

while [ $i -lt 4 ]; do # 4 ten-second intervals in 1 minute
  command/to/run & #run your command
  sleep 15
  i=$(( i + 1 ))
done
```

```bash
[label /etc/crontab]
* * * * * script.sh
```

### Every 30 seconds

```bash
[label script.sh]
i=0

while [ $i -lt 2 ]; do # 2 ten-second intervals in 1 minute
  command/to/run & #run your command
  sleep 30
  i=$(( i + 1 ))
done
```

```bash
[label /etc/crontab]
* * * * * script.sh
```

### Every 30 seconds (different way)

```bash
[label /etc/crontab]
* * * * * script.sh
* * * * * sleep 30 ; script.sh
```

[ad-uptime]