Run Jobs Every Twelve Hours at 6 AM and 6 PM | CronBase
0 6,18 * * * Twice daily at six in the morning and six in the evening.
The `0 6,18 * * *` cron expression schedules a task to execute twice every day at exactly 6:00 AM and 6:00 PM (18:00) in the system's local timezone. This twelve-hour interval is commonly used for morning readiness checks, shift-change reporting, and twice-daily database backups.
- Minute
- 0
- Hour
- 6,18
- Day of Month
- *
- Month
- *
- Day of Week
- *
Next 5 Runs
- in 9h 17m
- in 21h 17m
- in 1d 9h
- in 1d 21h
- in 2d 9h
* Tools
Code & Implementations
# Add to crontab using: crontab -e
# Runs at 6:00 AM and 6:00 PM daily. Logs output and errors to a file.
0 6,18 * * * /usr/local/bin/backup_script.sh >> /var/log/backup_cron.log 2>&1 › Setup notes
Open your system's crontab editor, paste the configuration line, and ensure the script is marked executable with chmod +x.
const cron = require('node-cron');
const { exec } = require('child_process');
// Schedule task to run at 06:00 and 18:00 daily
cron.schedule('0 6,18 * * *', () => {
console.log(`[${new Date().toISOString()}] Starting twice-daily synchronization job...`);
exec('/opt/scripts/sync.sh', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing sync script: ${error.message}`);
return;
}
if (stderr) {
console.warn(`Sync warning: ${stderr}`);
}
console.log(`Sync completed successfully: ${stdout}`);
});
}, {
scheduled: true,
timezone: 'UTC'
}); › Setup notes
Install node-cron via npm, save the script as scheduler.js, and run it using a process manager like PM2 to ensure continuous execution.
from apscheduler.schedulers.blocking import BlockingScheduler
import logging
import datetime
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def twice_daily_job():
logger.info(f'Job started at {datetime.datetime.now()}')
# Add business logic here
scheduler = BlockingScheduler(timezone='UTC')
# Trigger at 6 AM and 6 PM daily
scheduler.add_job(twice_daily_job, 'cron', hour='6,18', minute=0)
try:
logger.info('Starting scheduler...')
scheduler.start()
except (KeyboardInterrupt, SystemExit):
logger.info('Scheduler stopped.') › Setup notes
Install apscheduler via pip, configure the script with your business logic, and run it as a background service or daemon process.
package main
import (
"fmt"
"log"
"time"
"github.com/robfig/cron/v3"
)
func main() {
// Use NYC timezone to manage local business hours
nyc, err := time.LoadLocation("America/New_York")
if err != nil {
log.Fatalf("Failed to load timezone: %v", err)
}
c := cron.New(cron.WithLocation(nyc))
_, err = c.AddFunc("0 6,18 * * *", func() {
fmt.Printf("[%s] Running twice-daily database maintenance...\n", time.Now().Format(time.RFC3339))
})
if err != nil {
log.Fatalf("Error scheduling cron job: %v", err)
}
c.Start()
// Keep the main thread alive
select {}
} › Setup notes
Initialize a Go module, import robfig/cron/v3, build the binary, and run it on your target host.
package com.example.cron;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
public class TwiceDailyTask {
private static final Logger logger = LoggerFactory.getLogger(TwiceDailyTask.class);
// Runs at 6 AM and 6 PM every day in the configured timezone (defaulting to UTC here)
@Scheduled(cron = "0 0 6,18 * * *", zone = "UTC")
public void executeTask() {
logger.info("Executing scheduled twice-daily task...");
try {
// Business logic goes here
logger.info("Task execution completed successfully.");
} catch (Exception e) {
logger.error("Failed to execute scheduled task", e);
}
}
} › Setup notes
Ensure @EnableScheduling is active on your Spring Boot application class, and place this component inside your component scan path.
apiVersion: batch/v1
kind: CronJob
metadata:
name: twice-daily-cleanup
namespace: default
spec:
schedule: "0 6,18 * * *"
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
containers:
- name: worker
image: busybox:1.36
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- "echo 'Starting cleanup'; date; sleep 10; echo 'Cleanup finished'"
restartPolicy: OnFailure › Setup notes
Apply this configuration to your Kubernetes cluster using kubectl apply -f cronjob.yaml, ensuring your cluster clock is synchronized with NTP.
Last verified:
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.
cron(0 6,18 * * ? *) Systemd Timer
OnCalendar*-*-* 06,18:00:00
[Unit]
Description=Timer for cron expression: 0 6,18 * * *
[Timer]
OnCalendar=*-*-* 06,18:00:00
Persistent=true
[Install]
WantedBy=timers.target
Last verified:
Frequently Asked Questions
How does Daylight Saving Time (DST) affect this twice-daily schedule?
During DST transitions, the local time jumps. In spring, if the transition occurs at 2 AM, your 6 AM and 6 PM jobs run normally but the interval between them might temporarily be 11 or 13 hours. Ensure your cron daemon (like systemd-cron or cronie) is configured to use UTC to maintain a strict 12-hour interval.
Can I stagger execution to avoid database connection spikes at 06:00 and 18:00?
Yes, you can introduce a random start delay (jitter) within your execution script. For example, in Bash, use `sleep $((RANDOM % 300))` to delay the start by up to 5 minutes, spreading the resource load across your cluster.
How do I run this schedule on AWS ECS or AWS EventBridge?
In AWS EventBridge, standard cron syntax is supported but requires 6 fields. You must convert `0 6,18 * * *` to `cron(0 6,18 * * ? *)` or `cron(0 6,18 ? * * *)` depending on the target resource, specifying UTC explicitly.
What is the best way to monitor if both executions succeeded?
Implement dead man's snitches or heartbeat monitoring (e.g., Healthchecks.io). Configure the monitoring service to expect a ping twice daily with a 12-hour period and a grace period of 15 minutes to account for execution delays.
How can I change this to run every 12 hours starting from midnight instead?
If you want to shift the 12-hour interval to start at midnight and noon, modify the expression to `0 0,12 * * *`. This keeps the same frequency but aligns with traditional calendar day splits.
* Explore
Related expressions you might need
Last verified: