Back to Home

Cron Expression: Every 15 Minutes (*/15 * * * *)

CronOS Team
cronschedulingevery-15-minutesperiodic-taskstutorial

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 15 Minutes (*/15 * * * *)

The cron expression */15 * * * * executes a task every 15 minutes, making it one of the most standard intervals for periodic maintenance, reporting, and data processing tasks.

Expression Breakdown

bash
*/15 * * * *
│    │ │ │ │
│    │ │ │ └─── Day of week: * (every day)
│    │ │ └───── Month: * (every month)
│    │ └─────── Day of month: * (every day)
│    └───────── Hour: * (every hour)
└────────────── Minute: */15 (every 15 minutes)

Field Values

FieldValueMeaning
Minute*/15Every 15 minutes (0, 15, 30, 45)
Hour*Every hour (0-23)
Day of Month*Every day (1-31)
Month*Every month (1-12)
Day of Week*Every day of week (0-7)

Step Value Syntax

The /15 is a step value that means "every 15th minute starting from 0":

  • Runs at: 00:00, 00:15, 00:30, 00:45
  • Then repeats every hour: 01:00, 01:15, 01:30, 01:45, and so on

Common Use Cases

1. Report Generation

bash
*/15 * * * * /usr/bin/python3 /scripts/generate-reports.py

Generate periodic reports, analytics summaries, or data aggregations.

2. Database Maintenance

bash
*/15 * * * * /usr/local/bin/db-maintenance.sh

Run database cleanup, optimization, or index maintenance.

3. Backup Operations

bash
*/15 * * * * /usr/local/bin/incremental-backup.sh

Create incremental backups or snapshots of critical data.

4. Cache Refresh

bash
*/15 * * * * /usr/bin/python3 /scripts/refresh-cache.py

Refresh cached data, computed values, or API responses.

5. Queue Processing

bash
*/15 * * * * /usr/bin/node /app/process-queue.js

Process background job queues or message queues.

Execution Frequency

This expression runs 4 times per hour (96 times per day) at:

  • :00, :15, :30, :45 of every hour

Example Implementations

Report Generation Script

bash
#!/bin/bash
# /usr/local/bin/generate-reports.sh

LOCK_FILE="/tmp/report-generation.lock"
LOG_FILE="/var/log/reports.log"

# Prevent concurrent execution
if [ -f "$LOCK_FILE" ]; then
    echo "$(date): Report generation already running" >> $LOG_FILE
    exit 0
fi

touch $LOCK_FILE

# Generate reports
/usr/bin/python3 /scripts/generate-reports.py >> $LOG_FILE 2>&1

rm -f $LOCK_FILE

Python Report Generator

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

def generate_reports():
    conn = sqlite3.connect('/var/data/app.db')
    cursor = conn.cursor()
    
    # Get data from last 15 minutes
    since = datetime.now() - timedelta(minutes=15)
    
    # Aggregate metrics
    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
        FROM requests
        WHERE timestamp >= ?
    ''', (since,))
    
    metrics = cursor.fetchone()
    
    report = {
        'timestamp': datetime.now().isoformat(),
        'period': '15_minutes',
        'total_requests': metrics[0],
        'avg_response_time': round(metrics[1], 2) if metrics[1] else 0,
        'errors': metrics[2]
    }
    
    # Save report
    with open(f'/var/reports/report_{datetime.now().strftime("%Y%m%d_%H%M%S")}.json', 'w') as f:
        json.dump(report, f, indent=2)
    
    print(f"{datetime.now()}: Report generated: {report}")
    conn.close()

if __name__ == '__main__':
    generate_reports()

Database Maintenance Script

bash
#!/bin/bash
# /usr/local/bin/db-maintenance.sh

DB_NAME="app_db"
DB_USER="dbuser"
LOG_FILE="/var/log/db-maintenance.log"

# Vacuum SQLite database (if using SQLite)
if [ -f "/var/data/${DB_NAME}.db" ]; then
    sqlite3 "/var/data/${DB_NAME}.db" "VACUUM;" 2>> $LOG_FILE
    echo "$(date): Database vacuumed" >> $LOG_FILE
fi

# PostgreSQL maintenance (if using PostgreSQL)
# psql -U $DB_USER -d $DB_NAME -c "VACUUM ANALYZE;" >> $LOG_FILE 2>&1

# MySQL maintenance (if using MySQL)
# mysql -u $DB_USER -p$DB_PASS $DB_NAME -e "OPTIMIZE TABLE important_table;" >> $LOG_FILE 2>&1

Node.js Queue Processor

javascript
// process-queue.js
const Queue = require('bull');
const queue = new Queue('jobs', {
  redis: { host: 'localhost', port: 6379 }
});

async function processQueue() {
  const waiting = await queue.getWaiting({ limit: 100 });
  const delayed = await queue.getDelayed({ limit: 100 });
  
  console.log(`Processing ${waiting.length} waiting and ${delayed.length} delayed jobs`);
  
  // Process waiting jobs
  for (const job of waiting) {
    try {
      await job.process();
      console.log(`Processed job ${job.id}`);
    } catch (error) {
      console.error(`Job ${job.id} failed:`, error);
      await job.moveToFailed(error);
    }
  }
  
  // Check delayed jobs that are ready
  const now = Date.now();
  for (const job of delayed) {
    if (job.opts.delay && job.opts.delay <= now) {
      await job.promote();
    }
  }
}

processQueue().catch(console.error);

Best Practices

  1. Execution Window: Tasks should complete within 12-13 minutes
  2. Locking: Use file locks or distributed locks to prevent concurrent runs
  3. Error Handling: Implement comprehensive error handling and logging
  4. Idempotency: Design tasks to be safely re-runnable
  5. Resource Management: Monitor CPU, memory, and I/O usage

When to Use

Good for:

  • Report generation
  • Database maintenance
  • Incremental backups
  • Cache refresh operations
  • Queue processing
  • Data aggregation
  • Periodic cleanup tasks

Avoid for:

  • Real-time critical operations
  • Tasks requiring immediate execution
  • Very long-running processes (over 12 minutes)
  • Operations needing sub-15-minute precision

Comparison with Other Intervals

IntervalExpressionRuns/HourBest For
Every 10 minutes*/10 * * * *6More frequent tasks
Every 15 minutes*/15 * * * *4Standard intervals
Every 30 minutes*/30 * * * *2Less frequent tasks
Every hour0 * * * *1Hourly tasks

Real-World Example

A typical production setup:

bash
# Generate analytics reports
*/15 * * * * /usr/bin/python3 /scripts/generate-reports.py

# Database maintenance
*/15 * * * * /usr/local/bin/db-maintenance.sh

# Process job queue
*/15 * * * * /usr/bin/node /app/process-queue.js

Conclusion

The */15 * * * * expression is ideal for standard periodic tasks that don't require real-time execution. It's one of the most commonly used intervals in production environments, providing a good balance between keeping systems up-to-date and managing resource consumption efficiently.

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