Cron Job Every 5 Minutes: Complete Setup Guide (2025)
Running tasks every 5 minutes is one of the most popular cron job intervals for monitoring, API calls, queue processing, and real-time data updates.
This guide shows you exactly how to schedule a cron job every 5 minutes with practical examples and troubleshooting.
Quick Answer: Cron Expression for Every 5 Minutes
*/5 * * * * /path/to/your/script.sh
Breakdown:
*/5= Every 5 minutes (runs at :00, :05, :10, :15, :20, :25, :30, :35, :40, :45, :50, :55)*= Every hour*= Every day*= Every month*= Every day of week
Result: Your script executes 12 times per hour, 288 times per day.
How to Set Up a Cron Job Every 5 Minutes
Step 1: Open Crontab Editor
crontab -e
Step 2: Add Your Cron Job
*/5 * * * * /usr/bin/php /var/www/html/process.php
Step 3: Save and Exit
- Nano:
Ctrl+X, thenY, thenEnter - Vim:
Esc, then:wq, thenEnter
Step 4: Verify It's Scheduled
crontab -l
You'll see your cron job listed.
Real-World Examples
Example 1: PHP Script Every 5 Minutes
*/5 * * * * /usr/bin/php /var/www/html/cron/email-queue.php >> /var/log/cron-email.log 2>&1
What it does:
- Processes email queue every 5 minutes
- Logs output to file
- Captures errors
Example 2: Python Script with Virtual Environment
*/5 * * * * cd /home/user/myapp && /home/user/myapp/venv/bin/python check_api.py
What it does:
- Activates virtual environment
- Runs API health check
- Executes every 5 minutes
Example 3: Node.js Script
*/5 * * * * /usr/bin/node /home/user/app/scraper.js >> /var/log/scraper.log 2>&1
Example 4: Curl API Call Every 5 Minutes
*/5 * * * * curl -X POST https://api.example.com/ping -H "Authorization: Bearer TOKEN"
Example 5: Database Cleanup
*/5 * * * * /usr/bin/mysql -u root -pPASSWORD -e "DELETE FROM sessions WHERE expires < NOW()" mydb
Business Hours Only (9 AM - 5 PM)
Want to run every 5 minutes but only during work hours?
*/5 9-17 * * * /path/to/script.sh
Runs: Every 5 minutes from 9:00 AM to 5:55 PM
Weekdays Only (Monday - Friday)
*/5 9-17 * * 1-5 /path/to/script.sh
Runs: Every 5 minutes, business hours, weekdays only
Performance: Can My Server Handle Every 5 Minutes?
Running a script 288 times per day means:
✅ Safe for:
- API health checks (< 1 second)
- Queue processing (< 5 seconds)
- Log rotation
- Cache clearing
- Session cleanup
⚠️ Be Careful With:
- Database heavy operations
- Large file uploads
- Complex calculations
- External API calls (rate limits!)
Quick Calculation
If your script takes 2 seconds to run:
- Per hour: 12 runs × 2s = 24 seconds
- Per day: 288 runs × 2s = 576 seconds = 9.6 minutes total
That's 0.67% of your day processing. Very efficient!
Alternative Intervals Comparison
| Interval | Cron Expression | Runs Per Hour | Runs Per Day |
|----------|----------------|---------------|--------------|
| Every 1 minute | * * * * * | 60 | 1,440 |
| Every 5 minutes | */5 * * * * | 12 | 288 |
| Every 10 minutes | */10 * * * * | 6 | 144 |
| Every 15 minutes | */15 * * * * | 4 | 96 |
| Every 30 minutes | */30 * * * * | 2 | 48 |
Preventing Overlapping Executions
If your script might take longer than 5 minutes, use file locking:
*/5 * * * * flock -n /tmp/myscript.lock /path/to/script.sh
How it works:
flockcreates a lock file-n= non-blocking (skip if already running)- Prevents multiple instances running simultaneously
Common Mistakes & How to Fix Them
❌ Mistake 1: Running at Specific Minute Only
5 * * * * /script.sh # Only runs at :05 each hour, NOT every 5 minutes!
✅ Fix:
*/5 * * * * /script.sh
❌ Mistake 2: Script Not Executable
*/5 * * * * /path/to/script.sh # Permission denied!
✅ Fix:
chmod +x /path/to/script.sh
❌ Mistake 3: Relative Paths
*/5 * * * * ./script.sh # Cron doesn't know your current directory
✅ Fix: Use absolute paths:
*/5 * * * * /home/user/scripts/script.sh
❌ Mistake 4: Missing Environment Variables
Cron has a minimal environment. Your $PATH might not include /usr/local/bin:
✅ Fix: Set environment in crontab:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SHELL=/bin/bash
*/5 * * * * /path/to/script.sh
Troubleshooting: Cron Job Not Running Every 5 Minutes?
1. Check Cron Service is Running
sudo systemctl status cron
If stopped:
sudo systemctl start cron
sudo systemctl enable cron
2. Check Cron Logs
Ubuntu/Debian:
grep CRON /var/log/syslog | tail -50
CentOS/RHEL:
tail -50 /var/log/cron
3. Test Script Manually
/path/to/your/script.sh
If it fails manually, cron can't run it either.
4. Add Logging
*/5 * * * * /path/to/script.sh >> /tmp/cron-output.log 2>&1
Check the log:
tail -f /tmp/cron-output.log
5. Check Script Permissions
ls -l /path/to/script.sh
Should show -rwxr-xr-x (executable)
Different Start Times
Want to run every 5 minutes but start at :02?
2-59/5 * * * * /path/to/script.sh
Runs at: :02, :07, :12, :17, :22, :27, :32, :37, :42, :47, :52, :57
Or explicitly:
2,7,12,17,22,27,32,37,42,47,52,57 * * * * /path/to/script.sh
Real-World Use Cases
1. Social Media Monitoring
*/5 * * * * /usr/bin/python3 /home/user/monitor-mentions.py
Check Twitter/Reddit mentions every 5 minutes.
2. Stock Market Data
*/5 9-16 * * 1-5 /home/trader/fetch-prices.sh
Update stock prices during market hours.
3. Website Uptime Monitoring
*/5 * * * * curl -s -o /dev/null -w "%{http_code}" https://mysite.com | grep 200 || mail -s "Site Down!" admin@example.com
4. Queue Processing (Laravel)
*/5 * * * * cd /var/www/html && php artisan queue:work --stop-when-empty
5. Cache Warming
*/5 * * * * curl -s https://mysite.com/cache/warm > /dev/null 2>&1
Monitoring Your 5-Minute Cron Jobs
Running critical tasks every 5 minutes? Monitor them properly:
Cron Job Every 5 Minutes: Cheat Sheet
# Basic - Every 5 minutes, 24/7
*/5 * * * * /path/to/script.sh
# With logging
*/5 * * * * /path/to/script.sh >> /var/log/myscript.log 2>&1
# Business hours (9 AM - 5 PM)
*/5 9-17 * * * /path/to/script.sh
# Weekdays only
*/5 * * * 1-5 /path/to/script.sh
# Business hours + weekdays
*/5 9-17 * * 1-5 /path/to/script.sh
# With environment
*/5 * * * * /bin/bash -c 'source /home/user/.bashrc && /path/to/script.sh'
# Prevent overlapping
*/5 * * * * flock -n /tmp/script.lock /path/to/script.sh
# Start at :02 instead of :00
2-59/5 * * * * /path/to/script.sh
# PHP script
*/5 * * * * /usr/bin/php /var/www/cron.php
# Python script
*/5 * * * * /usr/bin/python3 /home/user/script.py
# Node.js script
*/5 * * * * /usr/bin/node /home/user/app.js
Disable/Stop Cron Job
Temporarily Disable (Comment Out)
crontab -e
Add # at the start:
# */5 * * * * /path/to/script.sh
Permanently Remove
crontab -e
Delete the line entirely.
Remove All Cron Jobs
crontab -r # WARNING: Deletes ALL your cron jobs!
Testing Without Waiting 5 Minutes
Method 1: Run Every Minute Temporarily
* * * * * /path/to/script.sh
Test for a few minutes, then change back to */5.
Method 2: Set Next Run Time
23 14 * * * /path/to/script.sh
Set to run at 2:23 PM today, observe, then change to */5.
Method 3: Manual Execution
/path/to/script.sh
System Crontab vs User Crontab
User Crontab (Recommended)
crontab -e
*/5 * * * * /home/user/script.sh
Runs as your user account.
System Crontab (Requires Root)
Edit /etc/crontab:
sudo nano /etc/crontab
Add:
*/5 * * * * username /path/to/script.sh
Must specify username.
Environment Variables in Cron
Cron runs with minimal environment. Add variables at the top of crontab:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SHELL=/bin/bash
MAILTO=admin@example.com
*/5 * * * * /path/to/script.sh
Or in the cron line:
*/5 * * * * ENV_VAR=value /path/to/script.sh
Performance Best Practices
1. Keep Scripts Fast
Target < 5 seconds execution time:
*/5 * * * * timeout 5 /path/to/script.sh
2. Use Background Jobs for Heavy Tasks
*/5 * * * * /path/to/script.sh &
3. Implement Exponential Backoff
If API calls fail, wait longer before retry.
4. Log Execution Times
*/5 * * * * time /path/to/script.sh >> /var/log/timing.log 2>&1
5. Monitor Resource Usage
*/5 * * * * /usr/bin/time -v /path/to/script.sh >> /var/log/resources.log 2>&1
Need Reliable Hosting for Frequent Cron Jobs?
Running tasks every 5 minutes (288 times/day) requires a stable server:
Conclusion
Setting up a cron job every 5 minutes is straightforward:
*/5 * * * * /path/to/your/script.sh
Key Points:
- ✅ Runs 12 times per hour (288 times per day)
- ✅ Use
*/5notation - ✅ Always use absolute paths
- ✅ Make scripts executable
- ✅ Add logging for debugging
- ✅ Use
flockto prevent overlaps - ✅ Monitor critical jobs
Next Steps:
Related Reading:
Keywords: cron job every 5 minutes, crontab 5 minutes, linux cron 5 min, run script every 5 minutes, cron expression 5 minutes, ubuntu cron every 5 minutes, php cron 5 minutes