From fc72ca8d95119f6c2e036e95e97f05b0c8dfea76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Garapich?= Date: Tue, 4 Jan 2022 02:41:21 +0100 Subject: [PATCH] feat(tf2-base): parse status command --- packages/tf2-base/healthcheck.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/tf2-base/healthcheck.sh b/packages/tf2-base/healthcheck.sh index d4ed74c..04b83e4 100755 --- a/packages/tf2-base/healthcheck.sh +++ b/packages/tf2-base/healthcheck.sh @@ -1,3 +1,18 @@ #!/bin/bash -"${SERVER_DIR}/rcon" -H ${IP/0.0.0.0/127.0.0.1} -p ${PORT} -P ${RCON_PASSWORD} status +status="$("${SERVER_DIR}/rcon" -H ${IP/0.0.0.0/127.0.0.1} -p ${PORT} -P ${RCON_PASSWORD} status)" || exit $? + +# extract hostname +if [[ $status =~ hostname:[[:space:]](.+)[[:space:]]version[[:space:]]:[[:space:]] ]]; then + echo "hostname: ${BASH_REMATCH[1]}" +fi + +# extract map +if [[ $status =~ map[[:space:]]+:[[:space:]]([a-zA-Z0-9_]+) ]]; then + echo "map: ${BASH_REMATCH[1]}" +fi + +# extract player count +if [[ $status =~ players[[:space:]]:[[:space:]]([0-9]+)[[:space:]]humans,[[:space:]][0-9]+[[:space:]]bots[[:space:]]\(([0-9]+)[[:space:]]max\) ]]; then + echo "players: ${BASH_REMATCH[1]}/${BASH_REMATCH[2]}" +fi