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.

TerminalNot started

Your machine is ready to start

Create a free account to open a machine and get graded.