HANDS-ON TASK · 1 OF 1

Automate log cleanup

Project: Automate log cleanup

You're a DevOps engineer at esc bash. The app server keeps filling up its disk with old log files, and nobody remembers to clear them by hand. Your job is to set up a cleanup that runs on a schedule and leaves a record of each run, so this stops being a manual chore.

Set up the project

Run this first. It prepares the machine for the task:

bash
curl -fsSL https://raw.githubusercontent.com/Esc-Bash/project-init-scripts/main/linux/project-1/init.sh | bash

This creates /var/log/escbash-app/ with one live log, app.log, and a handful of old rotated logs whose names end in .old.

What to build

  1. Create a script at /root/bin/cleanup.sh that deletes the old rotated logs (the files ending in .old) inside /var/log/escbash-app/, and prints one line each time it runs. The live app.log must be left alone. Make the script executable.
  2. Schedule the script in your crontab so it runs on its own. The scheduled line must append the script's output to /var/log/escbash-app/cleanup.log.
  3. Make sure /var/log/escbash-app/cleanup.log exists.
  4. Run the script once yourself so the old logs are actually cleared now, not just at the next scheduled time.

When the checks pass, press Submit.

Start the lab on the right to run checks.

Pass the checks to continue
Spin up a fresh environment and practice live.
linux-devops-basic · fresh machine · ready in under a minute