Custom File Descriptors: An Audit Channel with exec
MediumCommand Line Guru15-25 minEvery process gets stdin(0), stdout(1), stderr(2) — but you can open more. Use a custom file descriptor to keep an audit log separate from normal output, in one script.
Write /root/scripts/run.sh (assignment in /root/case/assignment.env — TAG, LOG) that:
1. opens fd 3 to the log — exec 3> "$LOG",
2. writes START $TAG to fd 3 (>&3),
3. prints ran $TAG to stdout,
4. writes END $TAG to fd 3,
5. closes fd 3 — exec 3>&-.
The audit lines land in the log; the ran line goes to the terminal — two separate channels. Grading runs the script with your assignment and a held-out one (different TAG and LOG), reads the log, and confirms the audit lines are not on stdout. See /root/case/brief.txt.
- Open a custom file descriptor to a file with exec 3>
- Write to it with >&3 while stdout stays clean
- Close it with exec 3>&-
- Keep the audit channel and the stdout channel separate
Hands-on lab: you work on a real Linux box in your browser, graded on the machine's actual state.
