Last active
March 26, 2023 20:36
-
-
Save Kr3m/a5885424749f75fd0e4dbe68c734756a to your computer and use it in GitHub Desktop.
Restart LinuxGSM based Left 4 Dead 2 server that is both empty and not running the default map.
This file contains hidden or 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
#!/bin/bash | |
#depends on gamedig being installed globally | |
#place in /home/l4d2server (can probably work with other LGSM servers with minor modifications). | |
gameserver="l4d2server" | |
game="left4dead2" | |
config_path="./lgsm/config-lgsm/$gameserver/" | |
server="1.1.1.1" #change to server ip | |
for i in $(find . -maxdepth 1 -name "$gameserver*" | sed 's|^./||'); do | |
defaultmap=$(grep -P '^(?=[\s]*+[^#])[^#]*(defaultmap)' $config_path$i.cfg | awk -F\" '{print $2}') | |
port=$(grep -P '^(?=[\s]*+[^#])[^#]*(port)' $config_path$i.cfg | grep -v 'client' | awk -F\" '{print $2}') | |
currentmap=$(gamedig --type $game $server:$port | jq '.map' | awk -F\" '{print $2}') | |
players=$(gamedig --type $game $server:$port | jq '.players | length') | |
if [[ "$currentmap" != "$defaultmap" && $players -eq 0 ]]; then | |
./$i restart | |
fi | |
done |
Will work with any LinuxGSM server that has gamedig support. Just change the gameserver to your gameserver, game to the gamedig game type, and server to either localhost or your server ip.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Next steps:
npm install gamedig -g
sudo apt install jq
crontab -e
*/5 * * * * /home/l4d2server/check.sh > /dev/null 2>&1