Back to Home

Cron Expression: Every Friday at Midnight (0 0 * * 5)

CronOS Team
cronschedulingweeklyfridaytutorial

Need to generate a cron expression?

Use CronOS to generate any cron expression you wish with natural language. Simply describe what you need, and we'll create the perfect cron expression for you. It's completely free!

Generate Cron Expression

Cron Expression: Every Friday at Midnight (0 0 * * 5)

The cron expression 0 0 * * 5 executes a task every Friday at midnight (00:00), making it ideal for end-of-workweek operations, weekly summaries, and tasks that should run when the business week ends.

Expression Breakdown

bash
0 0 * * 5
│ │ │ │ │
│ │ │ │ └─── Day of week: 5 (Friday)
│ │ │ └───── Month: * (every month)
│ │ └─────── Day of month: * (every day)
│ └───────── Hour: 0 (at hour 0, midnight)
└─────────── Minute: 0 (at minute 0)

Field Values

FieldValueMeaning
Minute0At minute 0
Hour0At hour 0 (midnight)
Day of Month*Every day (1-31)
Month*Every month (1-12)
Day of Week5Friday

Execution Time

This expression runs once per week at:

  • Friday 00:00 (midnight)

Common Use Cases

1. Weekly Summaries

bash
0 0 * * 5 /usr/bin/python3 /scripts/generate-weekly-summary.py

Generate weekly summaries or end-of-week reports.

2. Weekly Backups

bash
0 0 * * 5 /usr/local/bin/weekly-backup.sh

Create full weekly backups at the end of the workweek.

3. Data Archiving

bash
0 0 * * 5 /usr/local/bin/archive-weekly-data.sh

Archive weekly data or move it to long-term storage.

4. System Maintenance

bash
0 0 * * 5 /usr/local/bin/weekly-maintenance.sh

Run weekly system maintenance, cleanup, or optimization.

Example Implementations

Weekly Summary Script

python
# generate-weekly-summary.py
import json
from datetime import datetime, timedelta
import sqlite3

def generate_weekly_summary():
    conn = sqlite3.connect('/var/data/app.db')
    cursor = conn.cursor()
    
    # Get data from this week (Monday to Friday)
    end_date = datetime.now()
    start_date = end_date - timedelta(days=5)
    
    cursor.execute('''
        SELECT 
            COUNT(*) as total_requests,
            AVG(response_time) as avg_response_time,
            SUM(revenue) as total_revenue
        FROM requests
        WHERE timestamp >= ? AND timestamp < ?
    ''', (start_date, end_date))
    
    metrics = cursor.fetchone()
    
    summary = {
        'week_start': start_date.strftime('%Y-%m-%d'),
        'week_end': end_date.strftime('%Y-%m-%d'),
        'summary': {
            'total_requests': metrics[0],
            'avg_response_time': round(metrics[1], 2) if metrics[1] else 0,
            'total_revenue': round(metrics[2], 2) if metrics[2] else 0
        }
    }
    
    with open(f'/var/reports/weekly_summary_{end_date.strftime("%Y%m%d")}.json', 'w') as f:
        json.dump(summary, f, indent=2)
    
    print(f"{datetime.now()}: Weekly summary generated")
    conn.close()

if __name__ == '__main__':
    generate_weekly_summary()

Best Practices

  1. Workweek End: Friday midnight marks the end of the business week
  2. Error Handling: Implement comprehensive error handling and logging
  3. Locking: Use file locks to prevent concurrent execution
  4. Monitoring: Set up alerts for failed weekly jobs
  5. Resource Management: Weekly jobs may be heavier, monitor resources

When to Use

Good for:

  • Weekly summaries
  • Weekly backups
  • Data archiving
  • End-of-workweek operations
  • Weekly maintenance

Avoid for:

  • Real-time critical operations
  • Tasks requiring more frequent execution

Related Patterns

PatternExpressionDescription
Every Monday0 0 * * 1Start of workweek
Every Friday0 0 * * 5End of workweek
Every weekday0 0 * * 1-5Monday through Friday

Conclusion

The 0 0 * * 5 expression is perfect for weekly operations that should run at the end of the workweek. It's commonly used for weekly summaries, backups, and maintenance tasks, providing closure on the business week and preparing for the weekend.

Need to generate a cron expression?

Use CronOS to generate any cron expression you wish with natural language. Simply describe what you need, and we'll create the perfect cron expression for you. It's completely free!

Generate Cron Expression