Bird
Raised Fist0
Linux CLIscripting~20 mins

Cron log monitoring in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Cron Log Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Identify the cron job execution from log output
Given the following snippet from a cron log, what command was executed by cron?
Linux CLI
Jun 10 14:05:01 server CRON[12345]: (root) CMD (/usr/bin/backup.sh)
A/usr/bin/update.sh
B/usr/bin/cleanup.sh
C/usr/bin/restart.sh
D/usr/bin/backup.sh
Attempts:
2 left
💡 Hint
Look for the CMD part in the log line.
❓ Troubleshoot
intermediate
1:30remaining
Diagnose why a cron job did not run
You see no output or log entries for a cron job scheduled at 3 AM daily. Which of these is the most likely reason?
AThe system time is set correctly
BThe cron daemon is not running
CThe cron job script has execute permission
DThe cron job is listed in crontab -l
Attempts:
2 left
💡 Hint
If cron daemon is stopped, no jobs run or log.
❓ Configuration
advanced
2:00remaining
Configure cron to log all job outputs to a specific file
Which crontab entry correctly redirects both stdout and stderr of /usr/bin/script.sh to /var/log/script.log?
A0 2 * * * /usr/bin/script.sh > /var/log/script.log 2>&1
B0 2 * * * /usr/bin/script.sh 2> /var/log/script.log
C0 2 * * * /usr/bin/script.sh > /var/log/script.log
D0 2 * * * /usr/bin/script.sh 2>&1 > /var/log/script.log
Attempts:
2 left
💡 Hint
Redirect stdout first, then stderr to the same file.
✅ Best Practice
advanced
1:30remaining
Best practice for monitoring cron job failures
Which method is best to get notified immediately when a cron job fails?
ACheck cron logs manually every day
BWrite output to a local file only
CConfigure cron to send email on job failure
DIgnore failures if jobs run mostly fine
Attempts:
2 left
💡 Hint
Immediate notification helps quick response.
🧠 Conceptual
expert
2:00remaining
Understanding cron log rotation impact
If cron logs are rotated daily and compressed, what is a key consideration for long-term cron job monitoring?
AArchived logs must be decompressed to analyze older cron jobs
BCron jobs stop running after log rotation
CCron daemon automatically deletes old logs without compression
DLog rotation disables cron logging temporarily
Attempts:
2 left
💡 Hint
Compressed logs need special handling to read.

Practice

(1/5)
1. What is the main purpose of monitoring cron logs on a Linux system?
easy
A. To install new cron jobs automatically
B. To check if scheduled tasks ran successfully
C. To delete old cron jobs from the system
D. To speed up the execution of cron jobs

Solution

  1. Step 1: Understand cron job scheduling

    Cron jobs are scheduled tasks that run automatically at set times.
  2. Step 2: Purpose of cron log monitoring

    Monitoring cron logs helps verify if these tasks ran as planned and if there were any errors.
  3. Final Answer:

    To check if scheduled tasks ran successfully -> Option B
  4. Quick Check:

    Cron logs track task success = A [OK]
Hint: Cron logs show task run status, not installation or deletion [OK]
Common Mistakes:
  • Confusing cron log monitoring with job installation
  • Thinking cron logs speed up tasks
  • Assuming cron logs delete jobs automatically
2. Which command correctly shows the last 10 lines of the cron log file located at /var/log/cron?
easy
A. tail /var/log/cron
B. head /var/log/cron
C. cat /var/log/cron | grep last 10
D. grep last /var/log/cron

Solution

  1. Step 1: Understand the tail command

    The tail command shows the last lines of a file, defaulting to 10 lines.
  2. Step 2: Apply tail to cron log

    Using tail /var/log/cron displays the last 10 lines of the cron log file.
  3. Final Answer:

    tail /var/log/cron -> Option A
  4. Quick Check:

    Last 10 lines = tail [OK]
Hint: Use tail to see recent log entries quickly [OK]
Common Mistakes:
  • Using head shows first lines, not last
  • Incorrect grep syntax for line count
  • Confusing grep with tail for last lines
3. What will be the output of this command if the cron log contains these lines:
Jun 10 10:00:01 server CRON[1234]: (root) CMD (backup.sh)
Jun 10 10:05:01 server CRON[1235]: (root) CMD (cleanup.sh)
Jun 10 10:10:01 server CRON[1236]: (root) CMD (backup.sh)

Command: grep backup.sh /var/log/cron
medium
A. Jun 10 10:00:01 server CRON[1234]: (root) CMD (backup.sh) Jun 10 10:10:01 server CRON[1236]: (root) CMD (backup.sh)
B. Jun 10 10:05:01 server CRON[1235]: (root) CMD (cleanup.sh)
C. No output
D. Jun 10 10:00:01 server CRON[1234]: (root) CMD (backup.sh)

Solution

  1. Step 1: Understand grep filtering

    The grep backup.sh command filters lines containing 'backup.sh'.
  2. Step 2: Identify matching lines in the log

    Two lines contain 'backup.sh': the first and third lines.
  3. Final Answer:

    Both lines with backup.sh are shown -> Option A
  4. Quick Check:

    grep filters matching lines = C [OK]
Hint: grep shows all lines containing the search term [OK]
Common Mistakes:
  • Selecting only one matching line
  • Expecting output for unrelated terms
  • Thinking grep outputs no lines if multiple matches exist
4. You run grep CRON /var/log/cron | tail -5 but get no output, even though you know cron jobs ran recently. What is the most likely reason?
medium
A. Cron jobs do not write to /var/log/cron
B. The grep command syntax is incorrect
C. The tail command does not work with pipes
D. The cron log file is empty or missing

Solution

  1. Step 1: Check command correctness

    The command syntax is correct; grep filters lines with 'CRON', tail shows last 5 lines.
  2. Step 2: Consider log file state

    If no output appears, the log file may be empty or missing, so no lines match.
  3. Final Answer:

    The cron log file is empty or missing -> Option D
  4. Quick Check:

    No output usually means empty or missing file [OK]
Hint: No output often means empty or missing log file [OK]
Common Mistakes:
  • Blaming grep syntax when it is correct
  • Assuming tail can't work with pipes
  • Thinking cron never logs to /var/log/cron
5. You want to monitor cron logs in real-time to see new entries as they appear. Which command should you use?
hard
A. grep -r CRON /var/log/cron
B. cat /var/log/cron | head -n 10
C. tail -f /var/log/cron
D. less /var/log/cron

Solution

  1. Step 1: Understand real-time log monitoring

    Real-time monitoring means seeing new log lines as they are added.
  2. Step 2: Use tail with follow option

    tail -f keeps the file open and shows new lines live.
  3. Final Answer:

    tail -f /var/log/cron -> Option C
  4. Quick Check:

    tail -f shows live log updates [OK]
Hint: Use tail -f to watch logs live as they update [OK]
Common Mistakes:
  • Using grep -r which searches recursively, not live
  • Using head only shows start, not live updates
  • Using less does not auto-refresh new lines
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard