Bird
0
0

You want to schedule a data cleanup script to run at 11:30 PM on the last day of every month. Which cron entry achieves this?

hard🚀 Application Q9 of 15
Raspberry Pi - Data Logging and Databases
You want to schedule a data cleanup script to run at 11:30 PM on the last day of every month. Which cron entry achieves this?
A30 23 31 * * /home/pi/cleanup.sh
B30 23 28-31 * * [ "$(date -d tomorrow +\%d)" = "01" ] && /home/pi/cleanup.sh
C30 23 * * 7 /home/pi/cleanup.sh
D0 23 L * * /home/pi/cleanup.sh
Step-by-Step Solution
Solution:
  1. Step 1: Understand last day of month scheduling

    Cron alone cannot detect last day; a conditional check is needed.
  2. Step 2: Analyze 30 23 28-31 * * [ "$(date -d tomorrow +\%d)" = "01" ] && /home/pi/cleanup.sh

    Runs 11:30 PM on days 28-31, but only executes script if tomorrow is day 1 (last day).
  3. Step 3: Check other options

    30 23 31 * * /home/pi/cleanup.sh runs only on 31st (fails for months with fewer days), C runs Sundays, D uses unsupported 'L'.
  4. Final Answer:

    30 23 28-31 * * [ "$(date -d tomorrow +\%d)" = "01" ] && /home/pi/cleanup.sh -> Option B
  5. Quick Check:

    Last day needs date check in script [OK]
Quick Trick: Use date check for last day, cron alone can't detect it [OK]
Common Mistakes:
MISTAKES
  • Using 31 only (misses shorter months)
  • Using weekday for last day
  • Assuming 'L' works in standard cron

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes