AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   Script to restart empty LinuxGSM L4D2 servers not running the default map. (https://forums.alliedmods.net/showthread.php?t=334445)

Kr3m 09-24-2021 22:22

Script to restart empty LinuxGSM L4D2 servers not running the default map.
 
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


All times are GMT -4. The time now is 22:42.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.