0
0
Linux CLIscripting~30 mins

Cron log monitoring in Linux CLI - Mini Project: Build & Apply

Choose your learning style9 modes available
Cron Log Monitoring
📖 Scenario: You are a system administrator who wants to monitor cron job executions on a Linux server. Cron jobs run scheduled tasks, and their logs are stored in a system file. You want to check how many cron jobs ran successfully today.
🎯 Goal: Build a simple script that reads the cron log file, filters entries for today's date, counts how many cron jobs ran successfully, and displays the count.
📋 What You'll Learn
Use the grep command to filter cron logs by today's date
Use the grep command to filter successful cron job entries
Use the wc -l command to count the number of matching lines
Store intermediate results in variables
Print the final count with a descriptive message
💡 Why This Matters
🌍 Real World
System administrators often need to monitor cron jobs to ensure scheduled tasks run correctly and troubleshoot failures.
💼 Career
Knowing how to parse logs and automate monitoring with shell commands is a key skill for DevOps and system administration roles.
Progress0 / 4 steps
1
Set the date variable
Create a variable called today that stores the current date in the format MMM DD (e.g., Jun 15) using the date command.
Linux CLI
Need a hint?

Use date '+%b %e' to get the month abbreviation and day with a space for single-digit days.

2
Filter cron log entries for today
Use the grep command to filter lines from /var/log/cron that contain the date stored in the today variable. Store the result in a variable called today_logs.
Linux CLI
Need a hint?

Use double quotes around $today to expand the variable inside grep.

3
Count successful cron job runs
Use grep to filter lines from today_logs that contain the word CMD, which indicates a cron job command ran. Then use wc -l to count these lines. Store the count in a variable called success_count.
Linux CLI
Need a hint?

Use echo "$today_logs" | grep 'CMD' | wc -l to count matching lines.

4
Display the count of successful cron jobs
Print the message "Number of cron jobs run today: X" where X is the value of the success_count variable.
Linux CLI
Need a hint?

Use echo with double quotes and variable expansion to print the message.