Cron Expression: First Day of Every Month at Midnight (0 0 1 * *)
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!
Cron Expression: First Day of Every Month at Midnight (0 0 1 * *)
The cron expression 0 0 1 * * executes a task on the first day of every month at midnight (00:00), making it ideal for monthly reports, billing cycles, and monthly maintenance operations.
Expression Breakdown
0 0 1 * *
│ │ │ │ │
│ │ │ │ └─── Day of week: * (every day)
│ │ │ └───── Month: * (every month)
│ │ └─────── Day of month: 1 (first day)
│ └───────── Hour: 0 (at hour 0, midnight)
└─────────── Minute: 0 (at minute 0)
Field Values
| Field | Value | Meaning |
|---|---|---|
| Minute | 0 | At minute 0 |
| Hour | 0 | At hour 0 (midnight) |
| Day of Month | 1 | First day of month |
| Month | * | Every month (1-12) |
| Day of Week | * | Every day of week (0-7) |
Execution Time
This expression runs once per month at:
- 1st of every month at 00:00 (midnight)
Common Use Cases
1. Monthly Reports
0 0 1 * * /usr/bin/python3 /scripts/generate-monthly-report.py
Generate monthly analytics reports or summaries.
2. Monthly Billing
0 0 1 * * /usr/bin/python3 /scripts/process-monthly-billing.py
Process monthly billing cycles or invoices.
3. Monthly Backups
0 0 1 * * /usr/local/bin/monthly-backup.sh
Create full monthly backups of databases or systems.
4. Monthly Maintenance
0 0 1 * * /usr/local/bin/monthly-maintenance.sh
Run monthly database optimization, cleanup, or maintenance tasks.
5. Data Archiving
0 0 1 * * /usr/local/bin/archive-monthly-data.sh
Archive monthly data or move it to long-term storage.
Example Implementations
Monthly Report Script
# generate-monthly-report.py
import json
from datetime import datetime, timedelta
import sqlite3
def generate_monthly_report():
conn = sqlite3.connect('/var/data/app.db')
cursor = conn.cursor()
# Get data from last month
today = datetime.now()
first_day_last_month = (today.replace(day=1) - timedelta(days=1)).replace(day=1)
last_day_last_month = today.replace(day=1) - timedelta(days=1)
cursor.execute('''
SELECT
COUNT(*) as total_requests,
AVG(response_time) as avg_response_time,
COUNT(DISTINCT user_id) as unique_users,
SUM(revenue) as total_revenue
FROM requests
WHERE timestamp >= ? AND timestamp < ?
''', (first_day_last_month, today.replace(day=1)))
metrics = cursor.fetchone()
report = {
'month': first_day_last_month.strftime('%Y-%m'),
'month_start': first_day_last_month.strftime('%Y-%m-%d'),
'month_end': last_day_last_month.strftime('%Y-%m-%d'),
'metrics': {
'total_requests': metrics[0],
'avg_response_time': round(metrics[1], 2) if metrics[1] else 0,
'unique_users': metrics[2],
'total_revenue': round(metrics[3], 2) if metrics[3] else 0
}
}
with open(f'/var/reports/monthly_{first_day_last_month.strftime("%Y%m")}.json', 'w') as f:
json.dump(report, f, indent=2)
print(f"{datetime.now()}: Monthly report generated")
conn.close()
if __name__ == '__main__':
generate_monthly_report()
Best Practices
- Monthly Cycle: First of month marks a clean monthly boundary
- Error Handling: Implement comprehensive error handling and logging
- Locking: Use file locks to prevent concurrent execution
- Monitoring: Set up alerts for failed monthly jobs
- Resource Management: Monthly jobs may be heavier, monitor resources
When to Use
✅ Good for:
- Monthly reports
- Monthly billing
- Monthly backups
- Monthly maintenance
- Data archiving
❌ Avoid for:
- Tasks requiring more frequent execution
- Real-time critical operations
Related Patterns
| Pattern | Expression | Description |
|---|---|---|
| First day of month | 0 0 1 * * | Monthly at midnight |
| First day at 8 AM | 0 8 1 * * | Monthly at 8 AM |
| 15th of month | 0 0 15 * * | Mid-month |
Conclusion
The 0 0 1 * * expression is perfect for monthly operations that should run at the start of each month. It's commonly used for monthly reports, billing cycles, and maintenance tasks, providing a clean monthly cycle for recurring operations.
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!