Intermediate · 45 minutes · Guided lesson

Logging, tests and dry-run mode

Plan tests for a cleanup script that identifies old files but should not delete anything during dry run.

By the end of this lesson

  • Explain logging, tests and dry-run mode and when it matters
  • Perform a bounded practice or evidence-based scenario
  • Verify the result and communicate limitations

Your environment: Use an unprivileged account and a disposable Linux lab. Examples are illustrative; verify syntax and behaviour against the installed software documentation. Where a command could affect a live service, complete the supplied scenario offline. Setup help

Core concepts

Operational scripts need observable behaviour, predictable exit codes and a dry-run option for changes. Unit tests can cover parsing and decision logic; integration tests should use disposable fixtures. Keep logs useful but avoid secrets, credentials and unnecessary personal data.

Operational decisions should be grounded in scope, observable evidence and a clear success condition. Record the system, version, time window and assumptions. Distinguish what you observed from what you inferred, and avoid exposing credentials or personal data in notes.

A safe working method

Plan tests for a cleanup script that identifies old files but should not delete anything during dry run.

Begin with read-only inspection, change one variable at a time when practical, and preserve a recovery option before consequential work. If the environment differs from the scenario, stop and consult the relevant vendor or distribution documentation rather than guessing.

Interpret the outcome

Tests prove candidate selection, boundary dates, error handling and no mutation in dry-run mode.

A command or check provides limited evidence. Validate the result at the level that matters to the task, note any remaining uncertainty and communicate next steps clearly.

See it in context

Worked example

Illustrative checklist for a disposable lab or offline case study.

# Record context before acting
printf '%s\n' 'scope: disposable lab' 'goal: Logging, tests and dry-run mode' 'result: pending' > practice-notes.txt
cat practice-notes.txt

This example creates a local note only. Replace the placeholder with evidence from your own authorised lab; do not include secrets.

Your turn

Practical lab

Write acceptance criteria for a safe file-retention utility, including explicit scope and recovery limits.

Run commands in your own lab. This website displays instructions; the practice terminal below helps you rehearse the syntax.

1. Prepare your workspace

mkdir -p "$HOME/training4linux/extended-labs" && cd "$HOME/training4linux/extended-labs"
printf '%s\n' 'Practice case: Logging, tests and dry-run mode' > case-notes.txt

2. Complete the task

  1. Plan tests for a cleanup script that identifies old files but should not delete anything during dry run.
  2. Record the evidence you used and distinguish it from assumptions.
  3. Write a verification step, a stop condition and a safe cleanup or recovery note.

3. Check your result

  • Tests prove candidate selection, boundary dates, error handling and no mutation in dry-run mode.
  • The exercise stays within the disposable workspace or offline scenario.
  • The report names at least one limitation or uncertainty.
Need a hint?

Identify the scope, inspect the relevant evidence and choose the smallest check that distinguishes possible explanations.

Reveal a worked solution

Compare this with your approach after trying the task. More than one valid solution may exist.

Use the expected outcomes as a rubric. Explain why each check supports the conclusion; more than one safe method may be valid.

After the lab: No production changes are required. Remove only files created in the disposable practice directory if desired.

Common mistakes to avoid

  • Do not run unfamiliar commands with elevated privileges or against production systems.
  • Do not treat a successful command exit as proof of the full service outcome.

Check your understanding

Knowledge check

Answer all 3 questions correctly to pass. Retry as often as you need; your best score is kept.

1. Which statement best describes logging, tests and dry-run mode?
2. What should happen before a consequential operational change?
3. What does one successful check establish?

Your lesson progress

Not started · Best score: 0% · Attempts: 0

Practical completion is self-reported. Progress is linked to a private cookie in this browser and stored on the site. Clearing that cookie loses access to it. Manage or erase progress.

Keep the reference close

Further reading