Last active
June 4, 2019 09:40
-
-
Save kkamkou/0180c4230bf25b40b9e3f8c6f35d556a to your computer and use it in GitHub Desktop.
Primitive bash http server to serve the status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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