← Back to Automation Hub

Chapter 24: Cron Job Mastery

Real automation doesn't require a human to press "Enter." In Linux, the Cron daemon is our time-based job scheduler. It allows us to run scripts at specific intervals—daily, weekly, or even every minute.

1. Understanding the Cron Syntax

To master Cron, you must understand the five-star syntax. Each star represents a different unit of time:

* * * * *
min hour day month weekday

2. Accessing the Crontab

To edit your scheduled tasks in the Debian environment, use the command:

crontab -e

Note: If it's your first time, it might ask you to choose an editor. Select nano.

3. Automating Your Network Audit

Let's schedule the net_audit.py we created in Chapter 23 to run every Sunday at 11:00 PM. Add this line to the bottom of your crontab:

0 23 * * 0 /usr/bin/python3 /home/loy/Digital/net_audit.py

4. Monitoring Cron Logs

To check if your scheduled tasks are running correctly, you can view the system logs:

grep CRON /var/log/syslog

Next Chapter: Database Automation (Coming Soon)