Skip to content

Instantly share code, notes, and snippets.

@kkamkou
Last active June 4, 2019 09:40
Show Gist options
  • Save kkamkou/0180c4230bf25b40b9e3f8c6f35d556a to your computer and use it in GitHub Desktop.
Save kkamkou/0180c4230bf25b40b9e3f8c6f35d556a to your computer and use it in GitHub Desktop.
Primitive bash http server to serve the status
#!/usr/bin/env bash
# Example:
# script.sh /tmp/status [8080] [40]
while true; do
PERCENT=`(cat ${1} | grep "Load:" | cut -d" " -f2) 2>/dev/null`
STATUS=`[[ -z "${PERCENT}" || "${PERCENT}" -gt ${3-79} ]] && echo "503" || echo "204"`
echo -e "HTTP/1.1 ${STATUS} OK\r\n\r\n" | nc -l --send-only -p ${2-8080} 1>/dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment