#!/usr/bin/env bash
set -euo pipefail
export LC_ALL=C
work=$(mktemp -d './linux-lab.XXXXXX')
trap 'rm -rf -- "$work"' EXIT
umask 027
printf 'hello\n' > "$work/a file.txt"
stat -c 'new file mode=%a' -- "$work/a file.txt"
chmod 600 -- "$work/a file.txt"
stat -c 'changed file mode=%a' -- "$work/a file.txt"
mkdir -- "$work/private"
chmod 700 -- "$work/private"
stat -c 'directory mode=%a' -- "$work/private"
if (set +o pipefail; false | true); then echo 'without pipefail: success'; fi
if (set -o pipefail; false | true); then echo 'with pipefail: success'; else echo 'with pipefail: failure'; fi
printf 'name,score\nAlice,10\nBob,20\n' > "$work/scores.csv"
while IFS=, read -r name score; do
  [[ "$name" == name ]] && continue
  printf '%s=%s\n' "$name" "$score"
done < "$work/scores.csv"
printf '\nTool availability\n'
for cmd in top ps netstat ss lsof strace tcpdump df free vmstat iostat systemd-analyze; do
 if command -v "$cmd" >/dev/null 2>&1; then printf '%s=available\n' "$cmd"; else printf '%s=missing\n' "$cmd"; fi
done
printf '\nFilesystem containing workspace\n'
df -h .
printf '\nMemory snapshot\n'
free -m
printf '\nOne-second vmstat sample (first line is since boot)\n'
vmstat 1 2
printf '\nPID 1 command\n'
cat /proc/1/comm
