Common Cron Job Examples: 50+ Real-World Use Cases
This comprehensive collection of practical cron job examples will help you automate system administration, web development, database maintenance, monitoring, and more.
💡 How to Use These Examples
1. Find an example that matches your use case
2. Replace paths, commands, and parameters with your values
3. Test the command manually before adding to cron
4. Add proper logging: command >> /var/log/job.log 2>&1
5. Use our cron generator to validate timing
⏰ Basic Timing Patterns
Start with these fundamental scheduling patterns:
* * * * *
Every minuteUse for testing and high-frequency monitoring
*/5 * * * *
Every 5 minutesPerfect for API health checks and log rotation
0 * * * *
Every hourIdeal for cache clearing and data synchronization
0 0 * * *
Daily at midnightCommon for daily reports and cleanup tasks
0 9-17 * * 1-5
Business hoursEvery hour during weekday work hours
🖥️ System Administration Examples
Log Management & Cleanup
Clean temporary files weekly
0 2 * * 0 find /tmp -type f -atime +7 -delete
Removes files older than 7 days from /tmp every Sunday at 2 AM
Rotate application logs
0 0 * * * /usr/sbin/logrotate /etc/logrotate.conf
Runs log rotation daily at midnight
Clean old log files
0 3 * * * find /var/log -name "*.log" -mtime +30 -delete
Delete log files older than 30 days at 3 AM daily
System Monitoring
Monitor disk space
*/15 * * * * df -h | awk '$5 > 80' | mail -s "Disk Alert" admin@example.com
Sends email alerts when disk usage exceeds 80%
Monitor system load
*/5 * * * * uptime >> /var/log/system-load.log
Logs system load every 5 minutes
Check running services
*/10 * * * * systemctl is-active nginx || systemctl restart nginx
Restart nginx if not running, check every 10 minutes
🌐 Web Development Examples
Application Maintenance
Clear application cache
0 1 * * * /var/www/html/artisan cache:clear
Laravel cache clearing at 1 AM daily
Generate sitemap
0 2 * * * /usr/bin/php /var/www/generate-sitemap.php
Update website sitemap daily at 2 AM
Process queued jobs
* * * * * cd /var/www && php artisan queue:work --stop-when-empty
Process Laravel queue jobs every minute
Analytics & Reporting
Generate daily reports
0 7 * * * /usr/bin/python3 /scripts/daily-analytics.py
Run analytics script every morning at 7 AM
Weekly performance report
0 9 * * 1 /scripts/performance-report.sh | mail -s "Weekly Report" team@company.com
Email performance metrics every Monday at 9 AM
🗄️ Database Maintenance Examples
Database Backups
MySQL full backup
0 2 * * * mysqldump -u backup_user -p'password' --all-databases > /backups/mysql_$(date +%Y%m%d).sql
Daily MySQL backup at 2 AM with date stamp
PostgreSQL backup
0 3 * * * pg_dumpall -U postgres > /backups/postgresql_$(date +%Y%m%d).sql
Daily PostgreSQL backup at 3 AM
MongoDB backup
0 1 * * * mongodump --out /backups/mongodb_$(date +%Y%m%d)
Daily MongoDB backup at 1 AM
Database Optimization
MySQL table optimization
0 4 * * 0 mysqlcheck -u admin -p'password' --optimize --all-databases
Weekly MySQL optimization every Sunday at 4 AM
PostgreSQL vacuum
0 5 * * 0 vacuumdb -U postgres --all --analyze
Weekly PostgreSQL vacuum and analyze
🛡️ Security & Compliance Examples
Health Checks & Alerts
Website uptime check
*/5 * * * * curl -f https://example.com > /dev/null || echo "Site down" | mail -s "ALERT" admin@example.com
Check website every 5 minutes, send email if down
SSL certificate expiry check
0 9 * * * /scripts/ssl-check.sh example.com
Daily SSL certificate expiration check at 9 AM
Security Monitoring
Scan for failed login attempts
*/30 * * * * grep "Failed password" /var/log/auth.log | tail -20 | mail -s "Failed Logins" security@example.com
Monitor and report failed SSH login attempts every 30 minutes
Update security definitions
0 3 * * * freshclam && systemctl reload clamav-daemon
Update ClamAV virus definitions daily at 3 AM
💾 Backup & DevOps Examples
File Backups & Sync
Rsync backup to remote server
0 23 * * * rsync -avz --delete /important/data/ user@backup-server:/backups/$(hostname)/
Daily backup at 11 PM using rsync
S3 backup with compression
0 2 * * 0 tar -czf - /var/www | aws s3 cp - s3://my-backups/www-backup-$(date +%Y%m%d).tar.gz
Weekly compressed backup to AWS S3
Deployment & Testing
Auto-deploy from Git
*/10 * * * * cd /var/www && git fetch origin main && git reset --hard origin/main
Pull latest changes every 10 minutes
Run automated tests
0 6 * * 1-5 cd /var/www && ./vendor/bin/phpunit
Run test suite every weekday morning at 6 AM
Docker container cleanup
0 3 * * 0 docker system prune -f && docker volume prune -f
Clean up unused Docker resources weekly
🔧 Best Practices for Production Use
Always Include:
- • Absolute paths for all commands
- • Proper output redirection with logging
- • Error handling and exit codes
- • Lock files to prevent overlapping jobs
- • Email notifications for critical failures
Test Before Production:
- • Run commands manually first
- • Test with minimal cron environment
- • Verify file permissions and ownership
- • Check available disk space for outputs
- • Monitor initial runs carefully
Ready to create your own cron job? Use our interactive generator!
Generate Cron ExpressionRemember to test all cron jobs manually before adding them to production systems.
Need help with syntax? Try our cron generatoror learn about troubleshooting.