Skip to content

Automating Tasks with Cron Jobs – Ninja Moves in the Shadows!

A true ninja strikes when the time is right – and disappears without a trace. Wouldn’t it be cool if your Linux tasks worked the same way? 🎭

Enter cron jobs – the stealthy assassins of automation! With cron, your scripts will execute like a well-planned ninja attack, at exactly the right moment. 🕰⚔️

What Are Cron Jobs?

Cron jobs are Linux’s way of scheduling tasks. They work even when you’re sleeping, just like an undercover ninja! 😴🥷

Where do cron jobs live?

bash
crontab -e   # Edit the cron job file
crontab -l   # List all scheduled cron jobs

Scheduling Tasks Like a Stealthy Warrior

Every cron job follows a secret five-part code:

plaintext
* * * * * command_to_execute
| | | | |
| | | | └── Day of the week (0 - 6) [Sunday = 0]
| | | └──── Month (1 - 12)
| | └────── Day of the month (1 - 31)
| └──────── Hour (0 - 23)
└────────── Minute (0 - 59)

Example: Running a script every day at 3 AM

bash
0 3 * * * /home/developernoob/noobscripts/backup.sh

🕶 Boom! Your backups now happen automatically. No hands needed.

Writing Crontab Rules Like a Ninja

ScheduleExampleMeaning
Every minute* * * * * commandRuns every single minute (like a hyperactive ninja 🏃)
Every hour0 * * * * commandRuns at the start of every hour
Every day at 4 AM0 4 * * * commandRuns daily at 4 AM
Every Monday at 6 AM0 6 * * 1 commandRuns every Monday morning
First day of the month0 0 1 * * commandRuns on the 1st of every month

Example: A Sneaky Notification

Send yourself a message every morning at 7 AM to remember your ninja duties:

bash
0 7 * * * echo "Time to hack the planet! 🌍💻" | mail -s "Daily Ninja Alert" you@example.com

Built by noobs, for noobs, with love 💻❤️