Back to Blog

50 Useful Cron Job Examples for Linux

50 Useful Cron Job Examples for Linux
Command of the Day
crontab -l

What it does: Lists all scheduled cron jobs configured for the current user.

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

  1. Every single minute:
    * * * * * /usr/local/bin/ping_check.sh
    
  2. Every 2 minutes:
    */2 * * * * /home/ubuntu/status_check.sh
    
  3. Every 5 minutes:
    */5 * * * * /usr/bin/curl -s https://example.com/api/ping > /dev/null
    
  4. Every 10 minutes:
    */10 * * * * /usr/bin/php /var/www/artisan schedule:run
    
  5. Every 15 minutes:
    */15 * * * * /home/ubuntu/sync_cache.sh
    
  6. Every 30 minutes:
    */30 * * * * /home/ubuntu/cleanup_tmp.sh
    
  7. Every 45 minutes:
    */45 * * * * /home/ubuntu/check_queue.sh
    
  8. At the start of every hour (00 min):
    0 * * * * /home/ubuntu/hourly_summary.sh
    
  9. Every 2 hours:
    0 */2 * * * /home/ubuntu/refresh_tokens.sh
    
  10. Every 4 hours:
    0 */4 * * * /home/ubuntu/sync_s3.sh
    
  11. Every 6 hours (00:00, 06:00, 12:00, 18:00):
    0 0,6,12,18 * * * /usr/bin/certbot renew --quiet
    
  12. Every 12 hours (Midnight & Noon):
    0 0,12 * * * /home/ubuntu/vacuum_db.sh
    

2. Daily Scheduling Patterns

  1. Every day at midnight (00:00):
    0 0 * * * /home/ubuntu/daily_backup.sh
    
  2. Every day at 2:30 AM:
    30 2 * * * /home/ubuntu/backup_mysql.sh
    
  3. Every day at 4:00 AM:
    0 4 * * * /usr/bin/apt-get update && /usr/bin/apt-get clean
    
  4. Every day at 8:00 AM and 8:00 PM:
    0 8,20 * * * /home/ubuntu/digest_report.py
    
  5. Every weekday (Monday through Friday) at 9:00 AM:
    0 9 * * 1-5 /home/ubuntu/send_morning_alerts.sh
    
  6. Every weekend (Saturday and Sunday) at midnight:
    0 0 * * 6,0 /home/ubuntu/weekend_indexing.sh
    
  7. Every weekday morning every 30 minutes between 9 AM and 5 PM:
    */30 9-17 * * 1-5 /home/ubuntu/market_sync.sh
    
  8. Twice daily at 1:00 AM and 1:00 PM:
    0 1,13 * * * /home/ubuntu/rotate_logs.sh
    

3. Weekly, Monthly, and Yearly Patterns

  1. Every Sunday at 3:00 AM:
    0 3 * * 0 /home/ubuntu/weekly_archive.sh
    
  2. Every Monday at 6:00 AM:
    0 6 * * 1 /home/ubuntu/generate_weekly_stats.py
    
  3. First day of every month at midnight (00:00):
    0 0 1 * * /home/ubuntu/monthly_billing.sh
    
  4. 15th day of every month at noon (12:00):
    0 12 15 * * /home/ubuntu/mid_month_audit.sh
    
  5. Every quarter (1st of Jan, Apr, Jul, Oct) at 00:00:
    0 0 1 1,4,7,10 * /home/ubuntu/quarterly_report.sh
    
  6. Once a year (Jan 1st at midnight):
    0 0 1 1 * /home/ubuntu/annual_archive.sh
    

4. Special Shorthand Macros

  1. Run once on server boot:
    @reboot /home/ubuntu/scripts/startup_services.sh
    
  2. Run hourly:
    @hourly /home/ubuntu/hourly_check.sh
    
  3. Run daily:
    @daily /home/ubuntu/daily_maintenance.sh
    
  4. Run weekly:
    @weekly /home/ubuntu/weekly_cleanup.sh
    
  5. Run monthly:
    @monthly /home/ubuntu/monthly_tasks.sh
    
  6. Run yearly:
    @yearly /home/ubuntu/annual_cleanup.sh
    

5. Practical Sysadmin & Maintenance Tasks

  1. Automated MySQL Database Dump:
    0 2 * * * /usr/bin/mysqldump -u root -p'password' my_db | gzip > /backups/db_$(date +\%F).sql.gz
    
  2. Delete Files in /tmp Older Than 7 Days:
    0 3 * * * /usr/bin/find /tmp -type f -mtime +7 -delete
    
  3. Vacuum Systemd Journal Logs Every Week:
    0 4 * * 0 /usr/bin/journalctl --vacuum-time=14d
    
  4. Renew Let's Encrypt SSL Certificates Twice a Day:
    0 0,12 * * * /usr/bin/certbot renew --quiet --post-hook "systemctl reload nginx"
    
  5. Sync Directory to Remote Server with Rsync:
    0 1 * * * /usr/bin/rsync -avz -e ssh /var/www/ user@backup.rivincloud.in:/backups/www/
    
  6. Purge Redis Expired Keys:
    0 * * * * /usr/bin/redis-cli bgrewriteaof
    
  7. Check Free Disk Space and Alert if Below 10%:
    */15 * * * * /home/ubuntu/disk_alert.sh
    
  8. Clean Stale Docker Images and Volumes:
    0 5 * * 0 /usr/bin/docker system prune -af --volumes
    
  9. Restart a Stale Node.js Bot Every Midnight:
    0 0 * * * /usr/bin/pm2 restart discord-bot
    
  10. Archive Minecraft Server World:
    0 4 * * * /usr/bin/tar -czf /backups/mc_$(date +\%F).tar.gz /home/minecraft/server/world
    
  11. Synchronize Server Time via NTP/Chrony:
    0 0 * * * /usr/sbin/chronyd -q 'server pool.ntp.org iburst'
    
  12. Export Git Repository Backup:
    0 3 * * * cd /var/git/repo && /usr/bin/git bundle create /backups/repo.bundle --all
    
  13. Purge PHP Session Files Older Than 24 Hours:
    0 2 * * * /usr/bin/find /var/lib/php/sessions -type f -cmin +1440 -delete
    
  14. Rotate Application Log Files Manually:
    0 0 * * * /usr/sbin/logrotate /etc/logrotate.conf --force
    
  15. Fetch External IP Address and Update Dynamic DNS:
    */10 * * * * /home/ubuntu/update_ddns.sh > /dev/null 2>&1
    
  16. Run Laravel Worker Queue Once Every Minute:
    * * * * * cd /var/www/app && /usr/bin/php artisan schedule:run >> /dev/null 2>&1
    
  17. 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
    
  18. 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!