Cron expression for every 5 minutes during business hours
Runs every 5 minutes from 09:00 to 17:55, Monday to Friday.
*/5 9-17 * * 1-5Next 5 runs (your time zone: )
Field by field
| Field | Value | Meaning |
|---|---|---|
| Minute | */5 | every 5 minutes |
| Hour | 9-17 | at hour 09 through 17 |
| Day of month | * | every day of the month |
| Month | * | every month |
| Day of week | 1-5 | on Monday through Friday |
Use it in your scheduler
crontab
Run crontab -e and add a line. Cron uses the server's time zone, which is often UTC.
crontab line
*/5 9-17 * * 1-5 /usr/local/bin/my-job.sh >> /var/log/my-job.log 2>&1
Kubernetes CronJob
Set timeZone to run the schedule in a zone other than the cluster's default.
cronjob.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
name: my-job
spec:
schedule: "*/5 9-17 * * 1-5"
timeZone: "Etc/UTC"
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: my-job
image: busybox:1.36
command: ["sh", "-c", "date; echo Hello from Kubernetes"]
GitHub Actions
GitHub evaluates schedules in UTC and runs them on the default branch. Runs can start a few minutes late when GitHub is busy.
.github/workflows/scheduled.yml
on:
schedule:
- cron: '*/5 9-17 * * 1-5'
systemd timer
systemd timers use OnCalendar instead of cron syntax. Check the value with systemd-analyze calendar 'Mon..Fri 09..17:00/5', or generate the full service and timer.
Timer section
[Timer] OnCalendar=Mon..Fri 09..17:00/5 Persistent=true