7 Days to Die - Scripts

Post Reply
User avatar
LHammonds
Site Admin
Site Admin
Posts: 512
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

7 Days to Die - Scripts

Post by LHammonds » Thu Dec 24, 2015 1:14 pm

This will be a collection of Linux scripts to help automate things on a Linux server hosting a 7 Days to Die game.

User avatar
LHammonds
Site Admin
Site Admin
Posts: 512
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Re: 7 Days to Die - Scripts

Post by LHammonds » Thu Dec 24, 2015 1:20 pm

Install script for Expanded Player Storage mod by Valmar

Extract his .xml files somewhere on your server. Create an "install.sh" file in the same folder and copy/paste the script below into it. Make sure your "TargetDir" path matches your environment. Also make sure to set the correct permissions so it can run. e.g. "chmod 755 install.sh" and run it by typing "./install.sh"
#!/bin/bash ## Author: LHammonds ## Date: 2015-12-24 ## Version: 1.0 ## Verified on Ubuntu Server 14.04 LTS ## The TargetDir should point to the dedicated server config files. TargetDir=/home/sdtd/engine/Data/Config ## Make sure the path is correct. if [ ! -f "${TargetDir}/blocks.xml" ]; then echo "INVALID PATH: ${TargetDir}" exit 1 fi ## If no backup exists of the original files, make a backup. if [ ! -f "${TargetDir}/blocks.bak" ]; then echo "BACKUP: blocks.xml to blocks.bak" cp ${TargetDir}/blocks.xml ${TargetDir}/blocks.bak fi if [ ! -f "${TargetDir}/recipes.bak" ]; then echo "BACKUP: recipes.xml to recipes.bak" cp ${TargetDir}/recipes.xml ${TargetDir}/recipes.bak fi if [ ! -f "${TargetDir}/loot.bak" ]; then echo "BACKUP: loot.xml to loot.bak" cp ${TargetDir}/loot.xml ${TargetDir}/loot.bak fi ## Add extra line to end of file to avoid sed issue with pattern as last line. echo -e "\n " >> ${TargetDir}/blocks.xml echo -e "\n " >> ${TargetDir}/recipes.xml echo -e "\n " >> ${TargetDir}/loot.xml ## Add file contents just before the closing tag. echo "Patching blocks.xml" sed -i '/<\/blocks>/ { h r blocks.xml g N }' ${TargetDir}/blocks.xml echo "Patching recipes.xml" sed -i '/<\/recipes>/ { h r recipes.xml g N }' ${TargetDir}/recipes.xml echo "Patching loot.xml" sed -i '/<\/lootcontainers>/ { h r loot.xml g N }' ${TargetDir}/loot.xml echo "Done"

User avatar
LHammonds
Site Admin
Site Admin
Posts: 512
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Linux-Based Shutdown Script

Post by LHammonds » Sun Feb 28, 2016 12:13 pm

Here is a shutdown script which I tested on Ubuntu Server 14.04 and 16.04 LTS but should work for most other flavors of Linux since it uses Bash.

Create a file such as sdtd-shutdown.sh and set permissions on it:
mkdir -p /var/scripts/prod touch /var/scripts/prod/sdtd-shutdown.sh chown root:root /var/scripts/prod/sdtd-shutdown.sh chmod 755 /var/scripts/prod/sdtd-shutdown.sh
Add the following text to the script:
#!/bin/bash ############################################# ## Name : sdtd-shutdown.sh ## Version : 1.0 ## Date : 2016-01-18 ## Author : LHammonds ## Purpose : Warn players and shutdown game. ## Compatibility : Verified on Ubuntu Server 14.04 thru 16.04 LTS ## Requirements : Must be run as root. ## Parameters : #1 = 7dtd server instance name (required) ## Run Frequency : Can run as often as needed. ## Exit Codes : None ################ CHANGE LOG ################# ## DATE WHO WHAT WAS CHANGED ## ---------- --- ---------------------------- ## 2016-01-18 LTH Created script. ############################################# ## Import standard variables and functions. ## . /usr/local/lib/7dtd/common.sh LogFile="/var/log/sdtd-shutdown.log" ## Requirement Check: Script must run as root user. if [ "$(id -u)" != "0" ]; then ## FATAL ERROR DETECTED: Document problem and terminate script. echo -e "\nERROR: Root user required to run this script.\n" echo -e "Type 'sudo su' to temporarily become root user.\n" exit fi ## Check parameter. if [ "${1}" == "" ]; then echo -e "[ERROR] Missing required parameter. Enter the server instance." echo -e "Syntax: ${ScriptName} [ServerInstance]" echo -e "Example 1: ${ScriptName} alpha13" echo -e "Example 2: ${ScriptName} hamcraft" echo -e "Here is a list of valid instances:" 7dtd.sh instances list exit 1 else InstanceName="${1}" fi telnetCommand ${InstanceName} "say \"Server shutdown in 1 minute\"" sleep 30 telnetCommand ${InstanceName} "say \"Server shutdown in 30 seconds\"" sleep 20 telnetCommand ${InstanceName} "say \"Server shutdown in 10 seconds\"" sleep 7 telnetCommand ${InstanceName} "say \"Server shutdown in 3 seconds\"" sleep 1 telnetCommand ${InstanceName} "say \"Server shutdown in 2 seconds\"" sleep 1 telnetCommand ${InstanceName} "say \"Server shutdown in 1 second\"" sleep 1 telnetCommand ${InstanceName} "say \"Be right back!\"" sleep 1 telnetCommand ${InstanceName} "shutdown" echo "`date +%Y-%m-%d_%H:%M:%S` - [INFO] Shutting down ${InstanceName} instance." | tee -a ${LogFile}
You can then schedule it in the root account (accessible by doing "sudo su" from your admin account) and then type "crontab -e"

Example crontab schedule:
######################################## # Name: Crontab Schedule for root user # Author: LHammonds ############# Update Log ############### # 2016-01-18 - LTH - Created schedule ######################################## SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # Crontab SYNTAX: # minute(0-59) hour(0-23) day-of-month(1-31) month(1-12) day-of-week(0-6) command-to-execute # # Adjust the time clock # 0 1-23 * * * /usr/sbin/ntpdate ntp.ubuntu.com > /dev/null 2>&1 # # 7dtd: Shutdown 7dtd instances for daily reboot: # 0 3 * * * /var/scripts/prod/sdtd-shutdown.sh HamCraft > /dev/null 2>&1 0 3 * * * /var/scripts/prod/sdtd-shutdown.sh WalkingDead > /dev/null 2>&1 0 3 * * * /var/scripts/prod/sdtd-shutdown.sh Vanilla > /dev/null 2>&1 2 3 * * * /var/scripts/prod/reboot.sh
Summary of what it is doing:

The schedule is configured to run the script 3 times simultaneously at 3:00am to shutdown 3 instances of servers called "HamCraft", "WalkingDead" and "Vanilla"

The shutdown of the 7dtd instances should take just a little over 1 minute so a server-wide reboot script is scheduled to go off at 3:02am

While connected to one of the servers during this period, players will get a notice that the server will be shutdown in 1 minute. Then get another notice 30 seconds later, etc. and eventually get disconnected automatically when the instance is shutdown.

Reference: Originally posted on 7dtd forum.

User avatar
LHammonds
Site Admin
Site Admin
Posts: 512
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Horde Notification

Post by LHammonds » Tue May 09, 2017 7:30 am

Here is a horde notification script for players which I tested on Ubuntu Server 16.04 LTS but should work for most other flavors of Linux since it uses Bash.

Create a file such as sdtd-horde-notify.sh and set permissions on it:

Code: Select all

mkdir -p /var/scripts/prod
touch /var/scripts/prod/sdtd-horde-notify.sh
chown root:root /var/scripts/prod/sdtd-horde-notify.sh
chmod 755 /var/scripts/prod/sdtd-horde-notify.sh
Add the following text to the script:
#!/bin/bash ############################################################# ## Name : sdtd-horde-notify.sh ## Version : 1.0 ## Date : 2017-05-08 ## Author : LHammonds ## Purpose : Notify players once a day about approaching horde night. ## 1. Only process this script if there are players online. ## 2. Only process this script if the time is > 5:00 am in-game. ## 3. Finally, send chat message with how many days until horde night. ## Installation: Run from crontab every few minutes. ## Compatibility : Verified on Ubuntu Server 14.04 thru 16.04 LTS ## 7 Days to Die, Alpha 15.2 ###################### CHANGE LOG ########################### ## DATE VER WHO WHAT WAS CHANGED ## ---------- --- --- --------------------------------------- ## 2017-05-08 1.0 LTH Created script. ############################################################# . /usr/local/lib/7dtd/common.sh TempFile="/tmp/sdtd-gettime.txt" LastRun="/tmp/sdtd-lastrun.txt" ServerInstance="hamcraft" Hour2Notify=5 ## Send ListPlayers command results to a temporary file. telnetCommand ${ServerInstance} "lp" > ${TempFile} ## Get the last line of the file. Example: Total of 13 in the game PlayerCount=`tail -n 1 ${TempFile}` ## Get the 3rd column of the line. Example: 13 PlayerCount=`echo ${PlayerCount} | cut -d' ' -f3` ## Delete the temporary file. rm ${TempFile} if [[ ${PlayerCount} == 0 ]]; then ## No active players online. No need to send in-game message. echo "[INFO] No players online, aborting script." exit 0 fi ## Send gettime command results to a temporary file. telnetCommand ${ServerInstance} "gettime" > ${TempFile} ## Get the last line of the file. Example: Day 115, 05:22 DayLine=`tail -n 1 ${TempFile}` ## Get the 2nd column of the line. Example: 115, CurrentDay=`echo ${DayLine} | cut -d' ' -f2` ## Remove the comma. Example: 115 CurrentDay="${CurrentDay//,}" ## Get the in-game time. Example: 05:22 CurrentTime=`echo ${DayLine} | cut -d' ' -f3` ## Get the in-game hour. Example: 05 CurrentHour=`echo ${CurrentTime} | cut -d':' -f1` ## Force number to decimal (base 10) by removing any leading zeroes. Example: 5 CurrentHour=$((10#${CurrentHour})) ## Get the remainder from dividing by 7. Example: 3 Remainder=`expr ${CurrentDay} % 7` ## Subtract the remainder from 7 to get how many days until the 7th night. DaysToHorde=`expr 7 - ${Remainder}` if [[ ${CurrentHour} -gt ${Hour2Notify} ]]; then ## It is not too early in the day to send the notification. if [ -f ${LastRun} ]; then ## If last message sent was today, abort script. PriorDay=`tail -n 1 ${LastRun}` if [[ ${PriorDay} == ${CurrentDay} ]]; then ## Message already sent today, abort script. exit 0 else ## We are in a new day. if [[ ${Remainder} == 0 ]]; then telnetCommand ${ServerInstance} "say \"[ffff00][INFO] [00ff00]Horde night tonight!\"" else telnetCommand ${ServerInstance} "say \"[ffff00][INFO] [00ff00]${DaysToHorde} days until horde night.\"" fi ## Create last run file with date when message was sent. echo ${CurrentDay} > ${LastRun} fi else ## Messasge not sent today, send the chat message. if [[ ${Remainder} == 0 ]]; then telnetCommand ${ServerInstance} "say \"[ffff00][INFO] [00ff00]Horde night tonight!\"" else telnetCommand ${ServerInstance} "say \"[ffff00][INFO] [00ff00]${DaysToHorde} days until horde night.\"" fi ## Create last run file with date when message was sent. echo ${CurrentDay} > ${LastRun} fi else ## Too early in the morning to message players, abort script. exit 0 fi ## Delete the temporary file. rm ${TempFile}
You can then schedule it in the root account (accessible by doing "sudo su" from your admin account) and then type "crontab -e"

Example crontab schedule:
######################################## # Name: Crontab Schedule for root user # Author: LHammonds ############# Update Log ############### # 2016-01-18 - LTH - Created schedule ######################################## SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # Crontab SYNTAX: # minute(0-59) hour(0-23) day-of-month(1-31) month(1-12) day-of-week(0-6) command-to-execute # # Adjust the time clock # 0 1-23 * * * /usr/sbin/ntpdate ntp.ubuntu.com > /dev/null 2>&1 # # 7dtd: Notify players each in-game day about approaching horde night # */5 * * * * /var/scripts/prod/sdtd-horde-notify.sh HamCraft > /dev/null 2>&1 */5 * * * * /var/scripts/prod/sdtd-horde-notify.sh WalkingDead > /dev/null 2>&1 */5 * * * * /var/scripts/prod/sdtd-horde-notify.sh Vanilla > /dev/null 2>&1
Summary of what it is doing:

The schedule is configured to run the script every 5 minutes for instances of servers called "HamCraft", "WalkingDead" and "Vanilla"

Even though it runs often, it will only generate an in-game message once per day shortly after the desired hour...which is set to 5am in the script via the "Hour2Notify" variable.

Here are all the possible messages players will see in the game:
[INFO] 6 days until horde night. [INFO] 5 days until horde night. [INFO] 4 days until horde night. [INFO] 3 days until horde night. [INFO] 2 days until horde night. [INFO] 1 days until horde night. [INFO] Horde night tonight!

User avatar
LHammonds
Site Admin
Site Admin
Posts: 512
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Update Check

Post by LHammonds » Tue Jun 20, 2017 11:20 pm

Here is a Bash script that can get the latest stable and experimental build numbers as well as the locally installed build number. The "AppDir" variable is probably the only thing you need to modify to reflect your installation of 7 Days to Die.

/var/scripts/prod/sdtd-check-ver.sh

Code: Select all

#!/bin/bash
#############################################################
## Name : sdtd-check-ver.sh
## Version : 1.1
## Date : 2017-06-30
## Author : LHammonds
## Purpose: Determine build numbers on Steam and local machine
##          for the 7 Days to Die dedicated server on Linux.
## Compatiblity: Tested on Ubuntu Server 16.04 LTS
##               7 Days to Die Alpha 15.2 and 16.0
###################### CHANGE LOG ###########################
## DATE       VER WHO WHAT WAS CHANGED
## ---------- --- --- ---------------------------------------
## 2017-06-20 1.0 LTH Created script.
## 2017-06-30 1.1 LTH Corrected 7dtd.sh syntax output.
#############################################################

AppDir="/opt/sdtd"
AppID="294420"
FileInfo="/tmp/sdtd-info.txt"
FileBranch="/tmp/sdtd-branch.txt"
FilePublic="/tmp/sdtd-public.txt"
FileExp="/tmp/sdtd-exp.txt"

${AppDir}/steamcmd/steamcmd.sh +login anonymous +app_info_update 1 +app_info_print ${AppID} +quit > ${FileInfo}

## Get total number of lines in file.
TotalLines=`wc -l ${FileInfo} | cut -d " " -f1`

## Get line number of 1st search pattern: "branches"
Branches=`grep -n -m 1 branches ${FileInfo}|cut -d ':' -f 1`

## Create new file starting from prior search line.
sed -n "${Branches},${TotalLines}p" ${FileInfo} > ${FileBranch}

## Get line number of 2nd search pattern: "public"
Public=`grep -n -m 1 public ${FileBranch}|cut -d ':' -f 1`
## Create new file starting from public line
sed -n "${Public},${TotalLines}p" ${FileBranch} > ${FilePublic}
PublicBuild=`grep -n -m 1 buildid ${FilePublic}|cut -d '"' -f 4`
echo "Steam Stable Build = ${PublicBuild}"

## Get line number of 3rd search pattern: "latest_experimental"
Exp=`grep -n -m 1 latest_experimental ${FileBranch}|cut -d ':' -f 1`
## Create new file starting from latest_experimental line
sed -n "${Exp},${TotalLines}p" ${FileBranch} > ${FileExp}
ExpBuild=`grep -n -m 1 buildid ${FileExp}|cut -d '"' -f 4`
echo "Steam Experimental Build = ${ExpBuild}"

rm ${FileInfo}
rm ${FileBranch}
rm ${FilePublic}
rm ${FileExp}

LocalBuild=$(grep buildid "${AppDir}/engine/steamapps/appmanifest_${AppID}.acf" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\  -f3)
echo "Local Build = ${LocalBuild}"

echo ""
echo "Analysis"
echo "--------"

if [ "${LocalBuild}" -eq "${PublicBuild}" ]; then
  echo "You are running the current stable build."
fi
if [ "${LocalBuild}" -eq "${ExpBuild}" ]; then
  echo "You are running the current experimental build."
fi
if [ "${LocalBuild}" -lt "${PublicBuild}" ]; then
  echo "You should update your server using:"
  echo "   7dtd.sh updateengine"
fi
if [ "${LocalBuild}" -lt "${ExpBuild}" ]; then
  echo "You can upgrade to the latest experimental version using:"
  echo "   7dtd.sh updateengine --experimental"
fi
Example output:

Code: Select all

root@srv-AllocRulz:/# /var/scripts/test/sdtd-check-ver.sh
Steam Stable Build = 1642899
Steam Experimental Build = 1894130
Local Build = 1894130

Analysis
--------
You are running the current experimental build.
Original Post: 7daystoodie.com

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests