Run Every 12 Hours Cron Schedule | CronBase

cron expression Standard
$ 0 */12 * * *

Twice daily at midnight and noon

The `0 */12 * * *` cron expression schedules a task to run twice daily, specifically at midnight (12:00 AM) and noon (12:00 PM). This twelve-hour interval is ideal for medium-frequency maintenance tasks, database backups, and data synchronization processes that do not require real-time execution but must run regularly.

Minute
0
Hour
*/12
Day of Month
*
Month
*
Day of Week
*
How it works

Next 5 Runs

  • in 3h 20m
  • in 15h 20m
  • in 1d 3h
  • in 1d 15h
  • in 2d 3h

* Tools

Code & Implementations

Bash
#!/usr/bin/env bash
# System cron job implementation for twice-daily database backup
# Typically installed in /etc/cron.d/db-backup or via crontab -e

set -euo pipefail

BACKUP_DIR="/var/backups/postgres"
LOG_FILE="/var/log/db-backup.log"

# Ensure backup directory exists
mkdir -p "${BACKUP_DIR}"

echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] Starting semi-daily database backup..." >> "${LOG_FILE}"

# Execute backup with error handling
if pg_dump -U postgres prod_db | gzip > "${BACKUP_DIR}/db_backup_$(date +%Y%m%d_%H%M%S).sql.gz"; then
    echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] Backup completed successfully." >> "${LOG_FILE}"
else
    echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] ERROR: Database backup failed!" >&2
    # Send alert to monitoring system here (e.g., PagerDuty or curl webhook)
    exit 1
fi
Setup notes

Save this script to /usr/local/bin/db-backup.sh, make it executable, and add '0 */12 * * * /usr/local/bin/db-backup.sh' to your system crontab.

Last verified:

Partner BetterStack

Monitor this schedule in production

Get alerted the moment this cron job fails, is late, or doesn't run. BetterStack tracks execution, duration, and output — no infrastructure required.

Platform Equivalents

AWS EventBridge

Standard cron expressions often need conversion for AWS EventBridge schedules.

EventBridge Rule
cron(0 */12 * * ? *)

Systemd Timer

OnCalendar*-*-* 00/12:00:00

my-task.timer
[Unit]
Description=Timer for cron expression: 0 */12 * * *

[Timer]
OnCalendar=*-*-* 00/12:00:00
Persistent=true

[Install]
WantedBy=timers.target

Last verified:

Frequently Asked Questions

How does the 12-hour cron schedule react to Daylight Saving Time changes?

If your system timezone is set to local time, DST transitions can cause the job to run 11 or 13 hours apart, or skip/double-execute. To avoid this, always configure your cron daemon or scheduler to run in the UTC timezone, which does not observe DST.

Can I offset the execution time to avoid resource spikes at midnight and noon?

Yes. If you want to run every 12 hours but avoid the top of the hour, change the minute field. For example, `30 */12 * * *` will run at 12:30 AM and 12:30 PM, spreading the load away from other system processes starting on the hour.

What is the best way to monitor a job that only runs twice a day?

Passive monitoring (log parsing) is insufficient for twice-daily tasks. Use active push-based monitoring ('Dead Man's Switch') like Healthchecks.io. If the monitoring endpoint does not receive a ping within 12 hours plus a small grace buffer, it immediately triggers an alert.

How do I prevent a long-running 12-hour job from overlapping with its next run?

Use lock mechanisms or concurrency policies. In Kubernetes, set `concurrencyPolicy: Forbid`. In Linux bash scripts, wrap your execution using the `flock` utility (e.g., `flock -n /var/lock/myjob.lock mycommand`) to prevent concurrent execution if a previous run hangs.

Does `*/12` always run at exactly 00:00 and 12:00?

Yes, in standard cron implementations, the step value `*/12` divides the 24-hour day starting from 0. This results in executions at hour 0 (midnight) and hour 12 (noon). If you want specific hours like 6 AM and 6 PM, use explicit list notation: `0 6,18 * * *`.

* Explore

Related expressions you might need

Last verified:

Was this helpful?