Run Weekly Friday Afternoon Tasks | CronBase
0 17 * * 5 Every Friday afternoon at five o'clock
This cron expression schedules a task to execute weekly every Friday at exactly 5:00 PM. It is widely used in enterprise environments for compiling weekly business reports, triggering pre-weekend database backups, or shutting down non-essential staging environments to optimize cloud infrastructure costs over the weekend.
- Minute
- 0
- Hour
- 17
- Day of Month
- *
- Month
- *
- Day of Week
- 5
Next 5 Runs
- in 5d 20h
- in 12d 20h
- in 19d 20h
- in 26d 20h
- in 33d 20h
* Tools
Code & Implementations
#!/usr/bin/env bash
# System crontab entry for Friday 5:00 PM execution
# Save this to /etc/cron.d/friday_cleanup or install via 'crontab -e'
# Ensure the execution environment has correct paths
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# Run the weekly backup script and redirect both stdout and stderr to a log file
0 17 * * 5 /usr/local/bin/weekly-backup-runner.sh >> /var/log/weekly-backup.log 2>&1 › Setup notes
Add this line to your system crontab using 'crontab -e' or place it in a dedicated file under /etc/cron.d/ with proper user execution permissions.
const cron = require('node-cron');
const { exec } = require('child_process');
// Schedule task to run every Friday at 17:00 (5:00 PM)
cron.schedule('0 17 * * 5', () => {
console.log('[INFO] Initiating Friday afternoon teardown tasks...');
exec('/usr/local/bin/teardown-staging.sh', (error, stdout, stderr) => {
if (error) {
console.error(`[ERROR] Teardown failed: ${error.message}`);
return;
}
if (stderr) {
console.warn(`[WARN] Standard Error Output: ${stderr}`);
}
console.log(`[SUCCESS] Teardown output:\n${stdout}`);
});
}, {
scheduled: true,
timezone: "America/New_York"
}); › Setup notes
Install 'node-cron' using npm. This script schedules the task using a specified timezone to avoid issues with daylight saving transitions.
from apscheduler.schedulers.blocking import BlockingScheduler
import subprocess
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
def run_weekly_reports():
logger.info("Starting weekly business intelligence compilation...")
try:
result = subprocess.run(["/usr/bin/python3", "/app/generate_reports.py"], capture_output=True, text=True, check=True)
logger.info(f"Report generation completed successfully: {result.stdout}")
except subprocess.CalledProcessError as err:
logger.error(f"Failed to generate reports: {err.stderr}")
scheduler = BlockingScheduler()
# Trigger execution every Friday (day_of_week=4 or 'fri') at 17:00
scheduler.add_job(run_weekly_reports, 'cron', day_of_week='fri', hour=17, minute=0, timezone='UTC')
try:
logger.info("Starting APScheduler daemon...")
scheduler.start()
except (KeyboardInterrupt, SystemExit):
logger.info("Scheduler stopped cleanly.") › Setup notes
Install 'apscheduler' via pip, then run this script as a background daemon to execute the python task every Friday at 17:00 UTC.
package main
import (
"log"
"os/exec"
"time"
"github.com/robfig/cron/v3"
)
func main() {
// Use UTC timezone to prevent local DST shift issues
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 17 * * 5", func() {
log.Println("[INFO] Executing scheduled Friday environment shutdown...")
cmd := exec.Command("/bin/sh", "-c", "/usr/local/bin/stop-dev-servers.sh")
out, err := cmd.CombinedOutput()
if err != nil {
log.Printf("[ERROR] Shutdown script failed: %v, Output: %s", err, string(out))
return
}
log.Printf("[SUCCESS] Environment shutdown completed: %s", string(out))
})
if err != nil {
log.Fatalf("Error scheduling cron job: %v", err)
}
log.Println("Cron scheduler initialized. Waiting for Friday 17:00 EST...")
c.Start()
select {} // Keep application alive
} › Setup notes
Initialize a Go module, import 'github.com/robfig/cron/v3', and run this binary as a persistent background service.
package com.example.cron;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.logging.Logger;
@Component
public class FridayMaintenanceScheduler {
private static final Logger LOGGER = Logger.getLogger(FridayMaintenanceScheduler.class.getName());
// Standard cron format: second, minute, hour, day of month, month, day of week
// Spring supports standard 6-field cron patterns
@Scheduled(cron = "0 0 17 * * FRI", zone = "GMT")
public void runFridayMaintenance() {
LOGGER.info("Initiating Friday 5:00 PM GMT database optimization routines...");
try {
Process process = Runtime.getRuntime().exec("/usr/local/bin/optimize-db.sh");
int exitCode = process.waitFor();
if (exitCode == 0) {
LOGGER.info("Database optimization completed successfully.");
} else {
LOGGER.severe("Optimization failed with exit code: " + exitCode);
}
} catch (IOException | InterruptedException e) {
LOGGER.severe("Execution interrupted: " + e.getMessage());
Thread.currentThread().interrupt();
}
}
} › Setup notes
Ensure '@EnableScheduling' is declared on your main Spring Boot Application class. This component will automatically run the scheduled task.
apiVersion: batch/v1
kind: CronJob
metadata:
name: friday-resource-teardown
namespace: operations
spec:
schedule: "0 17 * * 5"
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 5
jobTemplate:
spec:
template:
spec:
containers:
- name: teardown-agent
image: bitnami/kubectl:latest
command:
- /bin/sh
- -c
- "kubectl scale deployment --replicas=0 -n staging -l auto-shutdown=true"
restartPolicy: OnFailure › Setup notes
Apply this manifest using 'kubectl apply -f
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 17 ? * 5 *) Systemd Timer
OnCalendarFri *-*-* 17:00:00
[Unit]
Description=Timer for cron expression: 0 17 * * 5
[Timer]
OnCalendar=Fri *-*-* 17:00:00
Persistent=true
[Install]
WantedBy=timers.target
Last verified:
Frequently Asked Questions
How does daylight saving time affect this Friday 5 PM schedule?
If your system clock is set to a local timezone that observes DST, the execution will shift relative to UTC twice a year. To maintain a consistent absolute interval or avoid running during transition hours, configure your cron daemon or orchestrator to run strictly on UTC.
Is it safe to run production deployments using this Friday afternoon cadence?
Generally, deploying software changes at 5:00 PM on a Friday is discouraged to prevent weekend on-call fatigue. However, it is an excellent window for read-only tasks, staging environment teardowns, or generating weekly performance metrics.
What happens if the server is offline at 17:00 on Friday?
Standard cron daemons will skip the execution entirely if the system is offline during the exact minute. If you require guaranteed execution once the server recovers, consider using tools like anacron or configuring a modern workflow orchestrator with retry policies.
How can I add a random delay to prevent resource spikes at 5:00 PM?
To prevent multiple instances from hitting your databases simultaneously, you can introduce a random sleep command in your execution script. For example, prepending 'sleep $((RANDOM % 300))' will spread the start times across a five-minute window.
Can I run this schedule on both Friday and Saturday at 5 PM?
Yes, you can modify the day-of-week field to include Saturday. By changing the expression to '0 17 * * 5,6', the system will trigger the specified job at 5:00 PM on both Fridays and Saturdays.
* Explore
Related expressions you might need
Last verified: