45/60
Sign inSign up free

401. Clean Up Temp Files with trap

medium 20 XP ~7 minHands-on lab

/home/student/bin/build.sh SRC OUT packs a folder into a tarball, using a scratch directory from mktemp. When it fails or is stopped, the scratch directories pile up in /tmp.

Task

Change build.sh so that its scratch directory is always removed:

  • when it succeeds
  • when it fails (for example, SRC does not exist), and it still exits with the same non-zero code as before
  • when it is stopped with SIGTERM while it runs (set BUILD_DELAY=20 to make it slow enough to stop)

It must keep producing the same tarball on success.

About this machine

Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.

Teaching or writing about this? Embed this lab on your page

TerminalNot started

Your machine is ready to start

A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.

No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.