Skip to content

Instantly share code, notes, and snippets.

@lhns
Last active November 28, 2025 09:16
Show Gist options
  • Select an option

  • Save lhns/efb7f4efeda416cd7648f0dc77614035 to your computer and use it in GitHub Desktop.

Select an option

Save lhns/efb7f4efeda416cd7648f0dc77614035 to your computer and use it in GitHub Desktop.
#!/bin/bash
(onrequest() {
hddtemp /dev/sd* /dev/nvme*n* | jq -Rr 'sub("(?<device>.*?): (?<model>.*?): (?<value>\\d*).*"; "hw.temperature{hw.model=\"\(.model)\",system.device=\"\(.device)\"} \(.value)")'
}; trap "exit 1" INT; while :; do content="$(onrequest; r=$?; echo /; exit "$r")"; { { echo -ne "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\nContent-Length: $(printf %s "${content%/}" | wc -c)\r\n\r\n"; printf %s "${content%/}"; } | nc -l $(printf -- "$(nc -h 2>&1 | head -n 1 | grep -q Ncat && echo "%s %s" || echo "-s %s -p %s")" 127.0.0.1 8080) >/dev/null; } & wait; done)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment