Sniper's Paradise!


The Shell Script Linux

Basic Shell Script for Unreal

By: Nathan Woodcock and MutantKiller

What is a Shell Script?

A Shell Script is similar to a WIN batch file, it is a file commonly created using any text editor such as GnomePad. It looks like name.sh . It is used to start or execute another command or set of commands which normally would be started from the a terminal screen. It contains a number of different commands which will all be executed by just one action. It can be used in the case of Unreal to start a server based on a set of arguments...specifying game type, maps, mutators,etc. also if your server were to crash the shell script can make a "CrashLog" to record the server log at the time of the crash. It can then restart your server automatically, if your computer is still working.

Here are a few shell scripts submitted by fellow server admin Nathan Woodcock:

It's really simple

This script which will actually create the crash log file described in the text above (it will append the date and time to a file every time the server starts up): We are going to call it Unrealstart.sh (original heh?).
I should mentioned here that I run my console in a screen, then detach from it. If you push it to the background with "&" you will not be able to get to the console again if you log out ie. no remote admin.

#!/bin/sh
while true
do
cd /usr/games/Unreal/System
date >> UCoop-restart.log
./ucc server SpireVillage?game=UnrealShare.CoopGame ini=ctfserver.ini
sleep 10
done

Thats it. Anytime ucc crashes cleanly, after a 10 second pause ( just to be safe ) it is restarted automatically.

No Crashlog

Some Admins only add a crashlog when they are testing a new mod or release. Otherwise you can get VERY large crashlog on a stable server, and if you restart it you've got all that extra space taken up on your HD in a second log. If you do not need the crashlog then here is another variation of the shell script.

#!/bin/sh
cd /usr/games/Unreal/System
while true
do ./ucc server SpireVillage?game=UnrealShare.CoopGame ini=coopserver.ini
sleep 10
done

Adding a mutator to your Ustart.sh

#!/bin/sh
cd /usr/games/Unreal/System
while true
do ./ucc server SpireVillage?game=UnrealShare.CoopGame?mutator=SP_MonsterHunt.StrongerMonster ini=coopserver.ini
sleep 10
done

Adding multiple mutators to the Ustart.sh

#!/bin/sh
cd /usr/games/Unreal/System
while true
do ./ucc server SpireVillage?game=UnrealShare.CoopGame?mutator=SP_MonsterHunt.StrongerMonster,SP_MonsterHunt.RegenerateAmmo ini=coopserver.ini
sleep 10
done

 

Finishing Touches

After you have made the script with a text editor, then do:

chmod +x Ustart.sh

then you can run it from the terminal screen:

./Ustart.sh


Advanced Shell Script

Well, just to jump on the scripting bandwagon (:-) i'm enclosing
the really overkill script that I use.

The nice thing about this script is it allows you to place a
command (by creating a file) to stop the server in place between
restarts. It also sends a notification email every time it restarts
and saves all the old log files into a directory for you.

I use this in combination with screen, so that no games are actually
running on a physical console, but i still have access to the game console
from anywhere.

#!/bin/bash
#
# Adjust these for your site
ADMIN="admin_email@my.domain.net"
MAP=CTF-Coret
GAMETYPE=BotPack.CTFGame
MUTATOR=BotPack.InstaGibDM
DIR=/opt/games/Unreal
PS="ps awx"
WAIT=20
#
# If you multihome your server, you can use the
# autoIP'r below, or hardcode it in
IP=`/sbin/ifconfig eth0 |grep 'inet addr:' | cut -f 2 -d: | awk '{print $1}'`
OPTIONS="ini=Unreal.ini" #multihome=$IP
#######################################################
# Shouldn't have to modify anything below
SDIR=$DIR/System
RUNNING=true
#
cd $SDIR
while (true);
do
if [ -e STOP.unreal ];
then
echo "Unreal administratively stopped" \
| mail -s "UnrealServer Admin" ${ADMIN} --
-fUnrealServer@${IP}
exit
else
SD=`date +'%Y%m%d%H%M'`
$SDIR/ucc server ${MAP}?game=${GAMETYPE}?mutator=${MUTATOR}
\
$OPTIONS LOG=Server-$SD.log | tee $DIR/ucc-$SD.log
while ($RUNNING);
do
$res=`$PS | grep ucc.server | grep -v grep | wc -l`
if [ $res -gt 0 ]; then
RUNNING=true
sleep ${WAIT}
else
RUNNING=false
fi
done
ED=`date +'%Y%m%d%H%M'`
mv $SDIR/Server-$SD.log $DIR/ServerLogs/$SD-$ED.log
mv $DIR/ucc-$SD.log $DIR/ServerLogs
for i in `ls $SDIR | grep -i log`; do
ADMMSG="${ADMMSG}\nFound other logfile $i"
mv $i $DIR/ServerLogs/`basename $i`.$ED
done
/bin/echo "${ADMMSG}\nUnreal restarted: Log=$SD-$ED.log" \
| mail -s "UnrealServer Admin" ${ADMIN} --
-fUnrealServer@${IP}
fi
done
##########################

If you have any questions on this script e-mail:

lsawyer@gci.com


For a listing of Command Line Options available click here



Spam Killer

Back To Top
2005 Sniper's Paradise
All logos and trademarks are properties of their respective owners.
Unreal™ is a registered trademark of Epic Games Inc.
Privacy Policy
Website by Softly
Powered by RUSH