Posts: 779
Threads: 5
Joined: Apr 2008
Reputation:
9
12-26-2008, 09:42 PM
(This post was last modified: 12-26-2008, 09:47 PM by Arjen.)
Make a script and add it to the crontab (crontab -e). For a every night replace at 4 AM add:
00 4 * * * /<path>/<script>.scr
Check paths, port, tickrate, servername etc. Script may look something like this (I did not test it!):
#-------------------------------------------------------
PATH=/bin:/usr/bin:/sbin:/usr/sbin
DIR=/<path>/srcds_l
PROC=27015
LOGFILE=/<path>/log.txt
NAME="Counter-Strike Source Public Server"
PARAMETERS="+maxplayers 16 +map de_dust2 +log on +ip <ip> -console -autoupdate -verify_all -tickrate 100 -port 27015"
#-------------------------------------------------------
# To stop the server
#-------------------------------------------------------
if [[ `ps -ef | grep $PROC|grep srcds` ]]
then
echo "Killing $NAME">>$LOGFILE
kill -9 `ps -ef |grep $PROC |awk '{print $2}'`
else
echo "$NAME is OFFLINE">>$LOGFILE
fi
#-------------------------------------------------------
# Updates the mapcycle and maplist
#-------------------------------------------------------
rm /<path>/srcds_l/cstrike/mapcycle.txt
rm /<path>/srcds_l/cstrike/maplist.txt
ls /<path>/srcds_l/cstrike/maps/*.bsp | awk -F "." '{print $1}' >> /<path>/srcds_l/cstrike/mapcycle.txt
ls /<path>/srcds_l/cstrike/maps/*.bsp | awk -F "." '{print $1}' >> /<path>/srcds_l/cstrike/maplist.txt
#-------------------------------------------------------
# Starts the server
#-------------------------------------------------------
if [[ `ps -ef | grep $PROC|grep srcds` ]]
then
echo "Can't start $NAME. Status: online">>$LOGFILE
else
echo "Starting $NAME">>$LOGFILE
if [ -e $DIR ];
then
cd $DIR
./srcds_run $PARAMETERS &
else
echo "$DIR doesn't exist">>$LOGFILE
fi
fi
exit 0