Back to Home

Cron Expression: Weekdays at 10:00 PM (0 22 * * 1-5)

CronOS Team
cronschedulingweekdayseveningtutorial

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: Weekdays at 10:00 PM (0 22 * * 1-5)

The cron expression 0 22 * * 1-5 executes a task on weekdays (Monday through Friday) at 10:00 PM (22:00), making it ideal for end-of-workday operations, daily summaries, and tasks that should run after business hours on workdays.

Expression Breakdown

bash
0 22 * * 1-5
│ │  │ │ │
│ │  │ │ └─── Day of week: 1-5 (Monday to Friday)
│ │  │ └───── Month: * (every month)
│ │  └─────── Day of month: * (every day)
│ └────────── Hour: 22 (at hour 22, 10:00 PM)
└───────────── Minute: 0 (at minute 0)

Field Values

FieldValueMeaning
Minute0At minute 0
Hour22At hour 22 (10:00 PM)
Day of Month*Every day (1-31)
Month*Every month (1-12)
Day of Week1-5Monday through Friday

Range Syntax

The 1-5 in the day of week field is a range that means "Monday through Friday":

  • Runs on: Monday, Tuesday, Wednesday, Thursday, Friday at 10:00 PM
  • Does NOT run on: Saturday, Sunday

Execution Time

This expression runs 5 times per week at:

  • Monday 22:00, Tuesday 22:00, Wednesday 22:00, Thursday 22:00, Friday 22:00

Common Use Cases

1. End-of-Workday Reports

bash
0 22 * * 1-5 /usr/bin/python3 /scripts/generate-end-of-day-report.py

Generate end-of-workday reports or summaries on weekdays.

2. End-of-Workday Backups

bash
0 22 * * 1-5 /usr/local/bin/end-of-day-backup.sh

Create daily backups after business hours on workdays.

3. End-of-Workday Data Processing

bash
0 22 * * 1-5 /usr/bin/python3 /scripts/process-end-of-day-data.py

Process daily data batches or aggregations after business hours.

4. End-of-Workday Cleanup

bash
0 22 * * 1-5 /usr/local/bin/end-of-day-cleanup.sh

Clean up temporary files, old cache entries, or stale data after work hours.

Example Implementations

End-of-Workday Report Script

python
# generate-end-of-day-report.py
import json
from datetime import datetime
import sqlite3

def generate_end_of_day_report():
    conn = sqlite3.connect('/var/data/app.db')
    cursor = conn.cursor()
    
    # Get today's data
    today = datetime.now().date()
    
    cursor.execute('''
        SELECT 
            COUNT(*) as total_requests,
            AVG(response_time) as avg_response_time,
            COUNT(CASE WHEN status_code >= 400 THEN 1 END) as errors,
            COUNT(DISTINCT user_id) as unique_users
        FROM requests
        WHERE DATE(timestamp) = ?
    ''', (today,))
    
    metrics = cursor.fetchone()
    
    report = {
        'date': today.strftime('%Y-%m-%d'),
        'day_type': 'business_day',
        'generated_at': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
        'metrics': {
            'total_requests': metrics[0],
            'avg_response_time': round(metrics[1], 2) if metrics[1] else 0,
            'errors': metrics[2],
            'unique_users': metrics[3]
        }
    }
    
    with open(f'/var/reports/end_of_day_{today.strftime("%Y%m%d")}.json', 'w') as f:
        json.dump(report, f, indent=2)
    
    print(f"{datetime.now()}: End-of-workday report generated")
    conn.close()

if __name__ == '__main__':
    generate_end_of_day_report()

Best Practices

  1. After Business Hours: 10 PM ensures tasks run after typical workday ends
  2. Weekdays Only: Excludes weekends from execution
  3. Error Handling: Implement comprehensive error handling and logging
  4. Locking: Use file locks to prevent concurrent execution
  5. Monitoring: Set up alerts for failed jobs

When to Use

Good for:

  • End-of-workday reports
  • End-of-workday backups
  • End-of-workday data processing
  • Tasks that should only run on weekdays
  • After-hours operations

Avoid for:

  • Tasks that need to run every day including weekends
  • Real-time critical operations
  • Very long-running processes

Related Patterns

PatternExpressionDescription
Weekdays at 10 PM0 22 * * 1-5End of workday, weekdays
Every day at 10 PM0 22 * * *Every day at 10 PM
Weekdays at 8 AM0 8 * * 1-5Start of workday

Conclusion

The 0 22 * * 1-5 expression is perfect for end-of-workday operations on weekdays only. It's commonly used for daily reports, backups, and data processing that should run after business hours, excluding weekends from the schedule.

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