Skip to content

Instantly share code, notes, and snippets.

@Kr3m
Last active March 26, 2023 20:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kr3m/a5885424749f75fd0e4dbe68c734756a to your computer and use it in GitHub Desktop.
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.
#!/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
@Kr3m
Copy link
Author

Kr3m commented Sep 26, 2021

Next steps:

  1. npm install gamedig -g
  2. sudo apt install jq
  3. crontab -e
  4. */5 * * * * /home/l4d2server/check.sh > /dev/null 2>&1

@Kr3m
Copy link
Author

Kr3m commented Mar 26, 2023

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