Scheduling automated tasks is essential for maintaining a healthy Linux server. Whether you need to run a task every minute, at specific times on weekdays, or once a year, crontab gives you precise control over system automation.
Here is a curated list of 50 practical cron job examples categorized by timing patterns and common server administration workflows for your RivinCloud VPS.
1. Minute and Hourly Scheduling Patterns
- Every single minute:
* * * * * /usr/local/bin/ping_check.sh - Every 2 minutes:
*/2 * * * * /home/ubuntu/status_check.sh - Every 5 minutes:
*/5 * * * * /usr/bin/curl -s https://example.com/api/ping > /dev/null - Every 10 minutes:
*/10 * * * * /usr/bin/php /var/www/artisan schedule:run - Every 15 minutes:
*/15 * * * * /home/ubuntu/sync_cache.sh - Every 30 minutes:
*/30 * * * * /home/ubuntu/cleanup_tmp.sh - Every 45 minutes:
*/45 * * * * /home/ubuntu/check_queue.sh - At the start of every hour (00 min):
0 * * * * /home/ubuntu/hourly_summary.sh - Every 2 hours:
0 */2 * * * /home/ubuntu/refresh_tokens.sh - Every 4 hours:
0 */4 * * * /home/ubuntu/sync_s3.sh - Every 6 hours (00:00, 06:00, 12:00, 18:00):
0 0,6,12,18 * * * /usr/bin/certbot renew --quiet - Every 12 hours (Midnight & Noon):
0 0,12 * * * /home/ubuntu/vacuum_db.sh
2. Daily Scheduling Patterns
- Every day at midnight (00:00):
0 0 * * * /home/ubuntu/daily_backup.sh - Every day at 2:30 AM:
30 2 * * * /home/ubuntu/backup_mysql.sh - Every day at 4:00 AM:
0 4 * * * /usr/bin/apt-get update && /usr/bin/apt-get clean - Every day at 8:00 AM and 8:00 PM:
0 8,20 * * * /home/ubuntu/digest_report.py - Every weekday (Monday through Friday) at 9:00 AM:
0 9 * * 1-5 /home/ubuntu/send_morning_alerts.sh - Every weekend (Saturday and Sunday) at midnight:
0 0 * * 6,0 /home/ubuntu/weekend_indexing.sh - Every weekday morning every 30 minutes between 9 AM and 5 PM:
*/30 9-17 * * 1-5 /home/ubuntu/market_sync.sh - Twice daily at 1:00 AM and 1:00 PM:
0 1,13 * * * /home/ubuntu/rotate_logs.sh
3. Weekly, Monthly, and Yearly Patterns
- Every Sunday at 3:00 AM:
0 3 * * 0 /home/ubuntu/weekly_archive.sh - Every Monday at 6:00 AM:
0 6 * * 1 /home/ubuntu/generate_weekly_stats.py - First day of every month at midnight (00:00):
0 0 1 * * /home/ubuntu/monthly_billing.sh - 15th day of every month at noon (12:00):
0 12 15 * * /home/ubuntu/mid_month_audit.sh - Every quarter (1st of Jan, Apr, Jul, Oct) at 00:00:
0 0 1 1,4,7,10 * /home/ubuntu/quarterly_report.sh - Once a year (Jan 1st at midnight):
0 0 1 1 * /home/ubuntu/annual_archive.sh
4. Special Shorthand Macros
- Run once on server boot:
@reboot /home/ubuntu/scripts/startup_services.sh - Run hourly:
@hourly /home/ubuntu/hourly_check.sh - Run daily:
@daily /home/ubuntu/daily_maintenance.sh - Run weekly:
@weekly /home/ubuntu/weekly_cleanup.sh - Run monthly:
@monthly /home/ubuntu/monthly_tasks.sh - Run yearly:
@yearly /home/ubuntu/annual_cleanup.sh
5. Practical Sysadmin & Maintenance Tasks
- Automated MySQL Database Dump:
0 2 * * * /usr/bin/mysqldump -u root -p'password' my_db | gzip > /backups/db_$(date +\%F).sql.gz - Delete Files in
/tmpOlder Than 7 Days:0 3 * * * /usr/bin/find /tmp -type f -mtime +7 -delete - Vacuum Systemd Journal Logs Every Week:
0 4 * * 0 /usr/bin/journalctl --vacuum-time=14d - Renew Let's Encrypt SSL Certificates Twice a Day:
0 0,12 * * * /usr/bin/certbot renew --quiet --post-hook "systemctl reload nginx" - Sync Directory to Remote Server with Rsync:
0 1 * * * /usr/bin/rsync -avz -e ssh /var/www/ user@backup.rivincloud.in:/backups/www/ - Purge Redis Expired Keys:
0 * * * * /usr/bin/redis-cli bgrewriteaof - Check Free Disk Space and Alert if Below 10%:
*/15 * * * * /home/ubuntu/disk_alert.sh - Clean Stale Docker Images and Volumes:
0 5 * * 0 /usr/bin/docker system prune -af --volumes - Restart a Stale Node.js Bot Every Midnight:
0 0 * * * /usr/bin/pm2 restart discord-bot - Archive Minecraft Server World:
0 4 * * * /usr/bin/tar -czf /backups/mc_$(date +\%F).tar.gz /home/minecraft/server/world - Synchronize Server Time via NTP/Chrony:
0 0 * * * /usr/sbin/chronyd -q 'server pool.ntp.org iburst' - Export Git Repository Backup:
0 3 * * * cd /var/git/repo && /usr/bin/git bundle create /backups/repo.bundle --all - Purge PHP Session Files Older Than 24 Hours:
0 2 * * * /usr/bin/find /var/lib/php/sessions -type f -cmin +1440 -delete - Rotate Application Log Files Manually:
0 0 * * * /usr/sbin/logrotate /etc/logrotate.conf --force - Fetch External IP Address and Update Dynamic DNS:
*/10 * * * * /home/ubuntu/update_ddns.sh > /dev/null 2>&1 - Run Laravel Worker Queue Once Every Minute:
* * * * * cd /var/www/app && /usr/bin/php artisan schedule:run >> /dev/null 2>&1 - Log Memory and CPU Usage to CSV:
*/5 * * * * echo "$(date),$(free -m | awk '/Mem:/ {print $3}'),$(top -bn1 | awk '/Cpu/ {print $2}')" >> /var/log/usage.csv - Auto Update ClamAV Antivirus Signatures:
0 1 * * * /usr/bin/freshclam --quiet
Common Mistakes
- Unescaped
%percent signs: In crontab,%is treated as a newline unless escaped with\%(e.g.,$(date +\%F)). - Missing executable permissions: Ensure your target shell script has
chmod +x.
Troubleshooting
- View cron execution history:
grep CRON /var/log/syslog | tail -n 20
Conclusion
This reference list covers virtually all common scheduling patterns needed for production servers. Use these examples to automate your workflows seamlessly on your RivinCloud VPS!
