View Single Post
Author Message
Kr3m
Junior Member
Join Date: Aug 2021
Old 09-24-2021 , 22:22   Script to restart empty LinuxGSM L4D2 servers not running the default map.
Reply With Quote #1

So, I wanted to create a script that could check if a server was empty and not running the default map and restart that server. This is it: (depends on gamedig being installed globally)

Code:
#!/bin/bash
gameserver="l4d2server"
game="left4dead2"
config_path="./lgsm/config-lgsm/$gameserver/"
server="1.1.1.1" #change to your 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
  1. Change server ip on line 5.
  2. Save to your server directory as an sh file e.g. check.sh
  3. Run crontab -e and paste this to run every 5 minutes: */5 * * * * /home/l4d2server/check.sh > /dev/null 2>&1
  4. Lastly, if you haven't already run npm install gamedig -g

Last edited by Kr3m; 09-26-2021 at 02:18.
Kr3m is offline