Crontab Mastery: Automate Anything on Linux

๐Ÿ“Œ Quick Summary
    ๐Ÿงฑ Table of Contents

    Cron lets you automate tasks like:

    • backups
    • scripts
    • monitoring
    • updates

    โš™๏ธ Edit Crontab

    crontab -e

    ๐Ÿงฉ Cron Syntax

    * * * * * command
    โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
    โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ Day of week (0-7)
    โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€ Month
    โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€ Day
    โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Hour
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Minute

    ๐Ÿงช Examples

    Run every minute:

    * * * * * /script.sh

    Every day at 2 AM:

    0 2 * * * /backup.sh

    Every Sunday:

    0 3 * * 0 /cleanup.sh

    ๐Ÿ“ฆ Real Use Case: Backup Script

    tar -czf backup.tar.gz /var/www

    Cron:

    0 1 * * * tar -czf /backup/site.tar.gz /var/www

    ๐Ÿ“œ View Jobs

    crontab -l

    โŒ Common Issues

    • PATH not set โ†’ use full paths:
    /usr/bin/php
    • Permissions issues
    • Script not executable:
    chmod +x script.sh

    ๐Ÿ”ฅ Pro Tips

    • Log output:
    0 2 * * * /script.sh >> /var/log/script.log 2>&1

    Use cron + systemd together for reliability


    ๐Ÿง  Summary

    Cron = free automation engine built into Linux.
    Once mastered, you save hours of manual work.


    ๐Ÿ”ฅ Why these are better for YOUR blog

    These fit perfectly with your structure:

    • Linux category = core OS knowledge
    • No overlap with:
      • Docker
      • Reverse proxy
      • DevOps pipelines

    Leave a comment

    Your email address will not be published. Required fields are marked *