Back to Home

Cron Expression: Every Minute (* * * * *)

CronOS Team
cronschedulingevery-minutemonitoringtutorial

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 Minute (* * * * *)

The cron expression * * * * * is the simplest and most frequent scheduling pattern, executing a task every single minute of every hour, every day.

Expression Breakdown

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

Field Values

FieldValueMeaning
Minute*Every minute (0-59)
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)

Common Use Cases

1. Health Checks and Monitoring

bash
* * * * * /usr/local/bin/health-check.sh

Continuously monitor system health, API endpoints, or service availability.

2. Real-Time Data Collection

bash
* * * * * /usr/bin/python3 /scripts/collect-metrics.py

Gather metrics, logs, or sensor data at high frequency.

3. Cache Refresh

bash
* * * * * /usr/local/bin/refresh-cache.sh

Keep frequently accessed data fresh in memory.

4. Queue Processing

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

Process job queues or message queues continuously.

Important Considerations

Resource Usage

Running tasks every minute can be resource-intensive. Consider:

  • CPU Impact: Ensure your task completes within 60 seconds
  • Memory: Monitor for memory leaks in long-running processes
  • I/O: Be mindful of disk and network operations
  • Database: Avoid heavy queries that could lock tables

Best Practices

  1. Lightweight Tasks: Keep execution time under 10-30 seconds
  2. Error Handling: Implement proper logging and error recovery
  3. Idempotency: Ensure tasks can run multiple times safely
  4. Monitoring: Track execution time and failures
  5. Rate Limiting: Respect API rate limits if making external calls

Example Implementations

System Monitoring Script

bash
#!/bin/bash
# /usr/local/bin/system-check.sh

# Check disk usage
df -h | grep -E '^/dev' | awk '{print $5}' | sed 's/%//' | while read usage; do
  if [ $usage -gt 90 ]; then
    echo "WARNING: Disk usage at ${usage}%" | logger -t cron
  fi
done

# Check memory
free | grep Mem | awk '{printf "Memory: %.2f%% used\n", $3/$2 * 100.0}'

Node.js Health Check

javascript
// health-check.js
const https = require('https');

https.get('https://api.example.com/health', (res) => {
  if (res.statusCode !== 200) {
    console.error(`Health check failed: ${res.statusCode}`);
    process.exit(1);
  }
  console.log('Health check passed');
}).on('error', (err) => {
  console.error(`Health check error: ${err.message}`);
  process.exit(1);
});

Python Metrics Collector

python
# collect-metrics.py
import psutil
import json
import time

metrics = {
    'timestamp': int(time.time()),
    'cpu_percent': psutil.cpu_percent(interval=1),
    'memory_percent': psutil.virtual_memory().percent,
    'disk_percent': psutil.disk_usage('/').percent
}

with open('/var/log/metrics.jsonl', 'a') as f:
    f.write(json.dumps(metrics) + '\n')

When to Use

Good for:

  • Health checks and monitoring
  • Real-time data collection
  • Lightweight queue processing
  • Cache warming
  • Status updates

Avoid for:

  • Heavy computations
  • Database migrations
  • Large file operations
  • Long-running processes
  • Tasks requiring more than 30 seconds

Alternative Patterns

If every minute is too frequent, consider:

  • Every 2 minutes: */2 * * * *
  • Every 5 minutes: */5 * * * *
  • Every 15 minutes: */15 * * * *

Conclusion

The * * * * * expression is powerful for real-time monitoring and data collection, but requires careful consideration of resource usage. Always ensure your tasks are lightweight, well-monitored, and can handle frequent execution without causing system strain.

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