How to Schedule Daily Tasks at 1:00 AM | CronBase
0 1 * * * Every day at one AM in the morning.
The `0 1 * * *` cron expression triggers a scheduled task once every day at exactly 1:00 AM. It is widely used in production environments for low-traffic operations such as database backups, log rotation, data archiving, and cache clearing to minimize performance impacts on active users.
- Minute
- 0
- Hour
- 1
- Day of Month
- *
- Month
- *
- Day of Week
- *
Next 5 Runs
- in 4h 23m
- in 1d 4h
- in 2d 4h
- in 3d 4h
- in 4d 4h
* Tools
Code & Implementations
#!/usr/bin/env bash
# Installs a cron job to run a backup script daily at 1:00 AM
set -euo pipefail
CRON_ENTRY="0 1 * * * /usr/local/bin/backup-db.sh >> /var/log/db-backup.log 2>&1"
# Safely append to crontab without duplicates
(crontab -l 2>/dev/null | grep -Fv "/usr/local/bin/backup-db.sh"; echo "$CRON_ENTRY") | crontab -
echo "Successfully scheduled daily backup job at 1:00 AM." › Setup notes
Save this script as setup-cron.sh, make it executable using chmod +x setup-cron.sh, and run it. Ensure that /usr/local/bin/backup-db.sh exists and is executable.
const cron = require('node-cron');
const { exec } = require('child_process');
// Schedule task to run daily at 1:00 AM in UTC timezone
cron.schedule('0 1 * * *', () => {
console.log('Starting daily maintenance job at 1:00 AM...');
exec('/usr/local/bin/daily-cleanup.sh', (error, stdout, stderr) => {
if (error) {
console.error(`Execution error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Stderr output: ${stderr}`);
}
console.log(`Stdout output: ${stdout}`);
});
}, {
scheduled: true,
timezone: "UTC"
}); › Setup notes
Install node-cron via npm (npm install node-cron) and run this script using Node.js to keep a long-running scheduling process active.
from apscheduler.schedulers.blocking import BlockingScheduler
import logging
import subprocess
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def run_daily_maintenance():
logger.info("Executing daily maintenance task at 1:00 AM")
try:
result = subprocess.run(["/usr/local/bin/daily-cleanup.sh"], capture_output=True, text=True, check=True)
logger.info(f"Job completed successfully: {result.stdout}")
except subprocess.CalledProcessError as err:
logger.error(f"Job failed with exit code {err.returncode}: {err.stderr}")
scheduler = BlockingScheduler(timezone="UTC")
# Trigger daily at 1:00 AM
scheduler.add_job(run_daily_maintenance, 'cron', hour=1, minute=0)
try:
scheduler.start()
except (KeyboardInterrupt, SystemExit):
logger.info("Scheduler stopped cleanly.") › Setup notes
Install APScheduler using pip (pip install apscheduler) and run the script as a daemon or background process.
package main
import (
"fmt"
"github.com/robfig/cron/v3"
"log"
"os/exec"
"time"
)
func main() {
utcLoc, err := time.LoadLocation("UTC")
if err != nil {
log.Fatalf("Failed to load UTC timezone: %v", err)
}
c := cron.New(cron.WithLocation(utcLoc))
_, err = c.AddFunc("0 1 * * *", func() {
log.Println("Running scheduled daily task at 1:00 AM UTC")
cmd := exec.Command("/usr/local/bin/daily-cleanup.sh")
out, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Execution failed: %v, output: %s", err, string(out))
return
}
log.Printf("Execution succeeded: %s", string(out))
})
if err != nil {
log.Fatalf("Error scheduling cron: %v", err)
}
c.Start()
fmt.Println("Cron scheduler started. Press Ctrl+C to exit.")
select {}
} › Setup notes
Initialize a Go module, run go get github.com/robfig/cron/v3, and compile or run this program to host the scheduler daemon.
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.logging.Logger;
@Component
public class DailyMaintenanceScheduler {
private static final Logger LOGGER = Logger.getLogger(DailyMaintenanceScheduler.class.getName());
// Runs every day at 1:00 AM (zone specified as UTC)
@Scheduled(cron = "0 0 1 * * *", zone = "UTC")
public void runDailyTask() {
LOGGER.info("Executing daily batch job at 1:00 AM UTC");
try {
// Insert business logic or system process execution here
LOGGER.info("Daily batch job completed successfully.");
} catch (Exception e) {
LOGGER.severe("Error running daily job: " + e.getMessage());
}
}
} › Setup notes
Ensure @EnableScheduling is active on your Spring Boot application class. This component will automatically be scanned and scheduled.
apiVersion: batch/v1
kind: CronJob
metadata:
name: daily-maintenance-job
namespace: default
spec:
schedule: "0 1 * * *"
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
containers:
- name: worker
image: alpine:latest
command: ["/bin/sh", "-c", "/usr/local/bin/daily-cleanup.sh"]
restartPolicy: OnFailure › Setup notes
Apply this manifest using kubectl apply -f cronjob.yaml. Note that Kubernetes cron schedules run in the timezone of the kube-controller-manager unless configured otherwise.
Last verified:
Keep this cron job monitored 24/7
UptimeRobot alerts you the moment a scheduled job stops responding. Free plan monitors up to 50 endpoints — no credit card required.
Platform Equivalents
AWS EventBridge
Standard cron expressions often need conversion for AWS EventBridge schedules.
cron(0 1 * * ? *) Systemd Timer
OnCalendar*-*-* 01:00:00
[Unit]
Description=Timer for cron expression: 0 1 * * *
[Timer]
OnCalendar=*-*-* 01:00:00
Persistent=true
[Install]
WantedBy=timers.target
Last verified:
Frequently Asked Questions
How does Daylight Saving Time affect a 1:00 AM cron schedule?
When using local time zones with Daylight Saving Time, the 1:00 AM hour can execute twice during the autumn transition (when clocks roll back from 2:00 AM to 1:00 AM). To prevent duplicate runs or missed executions during spring transitions, configure your server and cron daemon to use Coordinated Universal Time (UTC).
What happens if my daily 1:00 AM backup task overlaps with another cron job?
Running multiple heavy resource-intensive jobs simultaneously at 1:00 AM can cause CPU exhaustion and disk I/O bottlenecks. It is highly recommended to stagger your cron schedules (e.g., placing secondary tasks at 1:15 AM or 1:30 AM) or use a task queue to serialize execution.
Is it possible to run a job at 1:00 AM only on business days?
Yes, you can modify the day-of-week field (the fifth field) to target weekdays only. Changing the expression to `0 1 * * 1-5` will restrict the execution of your task to Monday through Friday at 1:00 AM, skipping weekend executions entirely.
How can I prevent a long-running 1:00 AM task from spawning a duplicate instance?
To prevent overlapping executions of a long-running job, wrap your command with a locking utility such as `flock` in Linux, or implement a distributed locking mechanism (like Redis-based Redlock) in your application code to ensure mutual exclusion.
How do I capture and monitor the output of a cron job scheduled at 1:00 AM?
You should redirect both standard output (stdout) and standard error (stderr) to a persistent log file or external log aggregator. For example, appending `>> /var/log/myjob.log 2>&1` to your crontab entry ensures all runtime information is captured for debugging.
* Explore
Related expressions you might need
Last verified: