Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Shell Script for Log Cleanup

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Shell Script for Log Cleanup. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given a list of log file paths, an integer days, and a boolean dry_run, write a Python function that generates a Bash shell script as a string. The script must delete .log files older than days days, skip missing files safely, and print each action. If dry_run is true, the script should print what it would delete without removing files.

Constraints

  • 1 <= len(log_paths) <= 10^3
  • 1 <= len(log_paths[i]) <= 300
  • 1 <= days <= 3650
  • Each path is a non-empty string
  • Only files ending with .log should be included in the generated script

Function Signature

def generate_log_cleanup_script(log_paths, days, dry_run):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output