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.
To master Cron, you must understand the five-star syntax. Each star represents a different unit of time:
0 0 * * * - Runs every day at midnight.*/15 * * * * - Runs every 15 minutes.0 12 * * 1 - Runs every Monday at 12:00 PM.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.
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
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)