## By request, server rotation bash script

Place for people to discuss public servers, and also for admins to lay out the details of their servers
Teppic
Private First Class
Posts: 575
Joined: Mon Mar 07, 2005 10:00 pm
Location: The North Block
Contact:

### By request, server rotation bash script

Here you go.

Code: Select all

#!/bin/bash
## Script for rotating bzfs server maps
## Put seperate config files for each map into a folder and direct CONFIGPATH to it
## or enter the path on the commandline
b=0
if [ $1 ]; then CONFIGPATH=$1
else
CONFIGPATH="/your/path/to/configfiles"
fi

until [ $b -lt 0 ]; do cd$CONFIGPATH
ls -1 > /tmp/confnos

LIMIT=$(awk 'END { print NR }' /tmp/confnos) for (( a=1; a <= LIMIT ; a++ )) do COM="NR=="$a
FILE=$(awk$COM /tmp/confnos)
FILE="$CONFIGPATH/$FILE"
bzfs -conf $FILE done done ## Due to my intetionally shoddy until loop this script will never exit. ## You can just update the config files in the path ## and they will be used on the next rotation cycle. ## Don't forget to add -g and -time ???? to the config files.  Last edited by Teppic on Wed Jun 22, 2005 5:39 pm, edited 1 time in total. ducatiwannabe Private First Class Posts: 3249 Joined: Tue Aug 10, 2004 3:55 pm Location: Planet Earth Contact: Ok, quick question. What is -g again? Also, do I put all this coding in the conf? WHere do I put the coding and how do I add the confs? ducatiwannabe Private First Class Posts: 3249 Joined: Tue Aug 10, 2004 3:55 pm Location: Planet Earth Contact: Never mind -g I got that. Do I put this code in the conf? ducatiwannabe Private First Class Posts: 3249 Joined: Tue Aug 10, 2004 3:55 pm Location: Planet Earth Contact: Ok I hooked it up, but I need a little bit of help. It says bad argument b=0 and then shuts off....why is this? I've hooked everthing up. Did you make an error in your code? Guest AFAIK, its a script that will run "bzfs -conf file"... then switch it over (when, I don't know). ducatiwannabe Private First Class Posts: 3249 Joined: Tue Aug 10, 2004 3:55 pm Location: Planet Earth Contact: Never mind. It won't work. It's linux. DOES ANYBODY have a rotation file for Windows? I can't find one anywhere! Teppic Private First Class Posts: 575 Joined: Mon Mar 07, 2005 10:00 pm Location: The North Block Contact: I may be able to do a batch file version for windoze later, this is a linux bash script. Guest What about Mac? No rush or anything. But if you get some free time... lol DTRemenak General Posts: 625 Joined: Thu Jan 16, 2003 4:54 am Location: U.S. Contact: Basic rotation batch file. Batch language sucks (just fyi). Code: Select all @ECHO OFF BREAK ON REM Batch file for rotating maps REM All paths should be in 8.3 notation e.g. progra~1 not program files REM Don't forget to add -g and -time <secs> to your conf files REM Press CTRL-C twice and "y" to answer "Terminate Batch Job (y/n)?" to exit REM Batch language is darn ugly, ain't it? REM This is set to the default install path of 2.0.2...you might have to change it SET BZFSPATH=c:\progra~1\bzflag~1.2\bzfs.exe REM This is the default conf path. If you supply an argument on the commandline it will override this. IF "%1" == "" SET CONFDIR=c:\your\path\to\conf\files IF NOT "%1" == "" SET CONFDIR=%1 :loop_top ECHO. FOR %%b IN (%CONFDIR%\*.conf) DO %BZFSPATH% -conf %%b ECHO "Reached end of rotation, starting over. GOTO loop_top  CBG, macs can use the shell script without a problem, if it was written right...you might need to make a few changes (e.g. using /bin/bash in the magic is nonstandard and nonportable outside of mainline linux distros). Last edited by DTRemenak on Wed Jun 22, 2005 6:39 pm, edited 1 time in total. Guest DTRemenak wrote:Basic rotation batch file. Batch language sucks (just fyi). Code: Select all @ECHO OFF BREAK ON REM Batch file for rotating maps REM All paths should be in 8.3 notation e.g. progra~1 not program files REM Press CTRL-C twice and "y" to answer "Terminate Batch Job (y/n)?" to exit REM Batch language is darn ugly, ain't it? REM This is set to the default install path of 2.0.2...you might have to change it SET BZFSPATH=c:\progra~1\bzflag~1.2\bzfs.exe REM This is the default conf path. If you supply an argument on the commandline it will override this. IF "%1" == "" SET CONFDIR=c:\your\path\to\conf\files IF NOT "%1" == "" SET CONFDIR=%1 :loop_top ECHO. FOR %%b IN (%CONFDIR%\*.conf) DO %BZFSPATH% -conf %%b ECHO "Reached end of rotation, starting over. GOTO loop_top  CBG, macs can use the shell script without a problem, if it was written right...you might need to make a few changes (e.g. using /bin/bash in the magic is nonstandard and nonportable outside of mainline linux distros). Ahhh... Sorry for the idiocy. I can hardly see what the script is actually doing, so changing it to suit is not gonna happen. If someone can explain it all here or PM, that would be great. Teppic Private First Class Posts: 575 Joined: Mon Mar 07, 2005 10:00 pm Location: The North Block Contact: ### Re: By request, server rotation bash script OK, for you mac users out there, this should run on OS X 10.1 , 10.2 and will run on 10.3 A much simplified script Code: Select all #!/bin/sh ## Script for rotating bzfs server maps ## Put seperate config files for each map into their own folder and direct CONFIGPATH to it b=0 CONFIGPATH="/path/to/config/files" cd$CONFIGPATH
until [ $b -lt 0 ]; do for FILE in * do RUNFILE=$CONFIGPATH"/"$FILE /path/to/bzfs/bzfs -conf$RUNFILE
done
done

## You can just update the config files in the path
## and they will be used on the next rotation cycle.
## Don't forget to add -g and -time ???? to the config files.
So, cut and paste the text into your favourite text editor (nano, emacs, kate etc)
Save the file as rotate.sh
Run

Code: Select all

chmod a+x rotate.sh
Run the command with

Code: Select all

./rotate.sh
It's important to have the full path to your map file in the config.

Edit: Exit the script, why would you want to do that?

Sir_Pants
Private First Class
Posts: 194
Joined: Mon Mar 28, 2005 2:41 am
Location: SOMEwhere in WA
so would two files look like this?

b=0
CONFIGPATH="/path/to/config/files"
cd $CONFIGPATH until [$b -lt 0 ]; do
for FILE in *
do
RUNFILE=$CONFIGPATH"/"$FILE
/path/to/bzfs/bzfs -conf $RUNFILE done done b=0 CONFIGPATH="/path/to/config/files" cd$CONFIGPATH
until [ $b -lt 0 ]; do for FILE in * do RUNFILE=$CONFIGPATH"/"$FILE /path/to/bzfs/bzfs -conf$RUNFILE
done
done
MONKEYPANTS.COM

Teppic
Private First Class
Posts: 575
Joined: Mon Mar 07, 2005 10:00 pm
Location: The North Block
Contact:
No, the script automatically detects how many different config files there are in the directory you tell it they are in, then runs each one in turn, when it's finished, it starts again.
To test if it is working change the last 3 lines to

Code: Select all


echo "/path/to/bzfs/bzfs -conf $RUNFILE" sleep 3 done done and when you run it it will sit there printing out the commands it would have run if you hadn't changed it. For example, I have 5 maps running on rotation at the moment, each has its own config file in /home/bzflag/confs , so if I ran the testing script I'd see Code: Select all /usr/bin/bzfs -conf /home/bzflag/confs/pants.conf then 3 seconds later Code: Select all /usr/bin/bzfs -conf /home/bzflag/confs/bigbox.conf and so on until Code: Select all /usr/bin/bzfs -conf /home/bzflag/confs/newmap.conf /usr/bin/bzfs -conf /home/bzflag/confs/sniper.conf /usr/bin/bzfs -conf /home/bzflag/confs/city.conf /usr/bin/bzfs -conf /home/bzflag/confs/pants.conf /usr/bin/bzfs -conf /home/bzflag/confs/bigbox.conf  is shown and it's started back at the begining with the first two again. Guest So, it is set to run the first conf untill "$b -lt 0", right?
What does "$b -lt 0" mean? When the player count is at 0? BinarySpike Corporal Posts: 735 Joined: Mon Mar 28, 2005 11:58 pm Contact: #!/bin/bash this is correct on mac. 10.2 and above at least...... Teppic Private First Class Posts: 575 Joined: Mon Mar 07, 2005 10:00 pm Location: The North Block Contact: CannonBallGuy wrote:So, it is set to run the first conf untill "$b -lt 0", right?
What does "\$b -lt 0" mean? When the player count is at 0?
No, it's a shoddy infinite loop, three lines above b is set to 0, then the line means until b is less than zero repeat below, but b never changes and the loop keeps getting repeated........

The script waits for the bzfs command to exit before it carries on, so the next map is run after the previous one exits.

Guest
So it won't change untill you use /shutdown or some other similar command like CTRL+C (mac) ?
I ask because I am trying to learn PHP and I want to learn C++ so any kind of programming is interesting.
How would you go about making it last a certain ammount of time before it changed?

Teppic
Private First Class
Posts: 575
Joined: Mon Mar 07, 2005 10:00 pm
Location: The North Block
Contact:
CannonBallGuy wrote:How would you go about making it last a certain ammount of time before it changed?
There are two ways, 1 is to use the -g (serve one game and exit) option of bzfs with the -time option so when the time expires the server shuts itself down. 2 would be to run the bzfs command with & at the end, then the script would continue to run, by adding the lines

Code: Select all

sleep 600
sleep 20
bzadmin gameover@127.0.0.1:5154 /password=password /shutdown /quit
the script would pause for the time set at the sleep command (10 minutes here0 then run bzadmin to shutdown the server.I think -g -time 600 is cleaner, but the second way could allow you to 'stop' the script (ctrl-z) for any ammount of time you like (like if you have a really good flag and sniper position lol) and 'unstop' it later with fg in the command line. Also if your player allocation for observer team is full up the shutdown commands may not be able to logon to the server to shut it down.

Guest

ducatiwannabe
Private First Class
Posts: 3249
Joined: Tue Aug 10, 2004 3:55 pm
Location: Planet Earth
Contact:
@ECHO OFF
BREAK ON

REM Batch file for rotating maps
REM All paths should be in 8.3 notation e.g. progra~1 not program files
REM Press CTRL-C twice and "y" to answer "Terminate Batch Job (y/n)?" to exit
REM Batch language is darn ugly, ain't it?

REM This is set to the default install path of 2.0.2...you might have to change it
SET BZFSPATH=c:\progra~1\bzflag~1.2\bzfs.exe

REM This is the default conf path. If you supply an argument on the commandline it will override this.
IF "%1" == "" SET CONFDIR=c:\your\path\to\conf\files
IF NOT "%1" == "" SET CONFDIR=%1

:loop_top

ECHO.
FOR %%b IN (%CONFDIR%\*.conf) DO %BZFSPATH% -conf %%b
ECHO "Reached end of rotation, starting over.

GOTO loop_top
So is this a windows script?

DTRemenak
General
Posts: 625
Joined: Thu Jan 16, 2003 4:54 am
Location: U.S.
Contact:
Yes. Just copy it into notepad and save it as "something.bat" (remember to set "Save as Type" to "All Types" otherwise it will actually save it as "something.bat.txt"). Also remember to change the paths to the ones your computer actually uses.

Spazzy McGee
Sergeant Major
Posts: 1403
Joined: Mon Mar 21, 2005 4:59 pm
Location: Planet MoFo, Sheffield Division; United Kingdom
Contact:

### AppleScript Rotator

Here Is a rotator i made in applescript for mac users.

(lol, applescript is so good)

Code: Select all


(*
This applescript will rotate conf files in a folder. make sure that the conf files have the '-time' command
in them, because the script will move to the next conf after the shell script ends.
*)

try
set LibraryConfig to list folder "(*PATH TO FOLDER OF CONF FILES*)" without invisibles
on error
set LibraryConfig to {"No Files"}
end try
set Filecount to the number of items in LibraryConfig
repeat
try
set x to the text returned of (display dialog "number of rotations:" default answer "")
set n to ((x) as number)
set goodnumber to true
exit repeat
on error
display dialog "Not A Number!"
end try
end repeat
set theNum to 1
repeat n times
set autoconf to ((item theNum of LibraryConfig) as string)
set endConf to "/bzflagserver/rotations/" & autoconf
delay 2.5
do shell script "/Applications/BZFlag-2.0.2.app/Contents/MacOS/bzfs -conf " & endConf (*Put the path to your bzfs *)
if theNum is (Filecount) then
set theNum to 1
else
set theNum to theNum + 1
end if
end repeat


Tell me what you think.

Spazzy
"Life is what happens to you while you're busy making other plans." - John Lennon

Molotovian
Private First Class
Posts: 52
Joined: Mon Oct 31, 2005 4:27 am
Location: Sniper's Nest
Thx for the mac code, this really helped.
,/../,('_') Molotovian ('_'),\..\,

Teppic
Private First Class
Posts: 575
Joined: Mon Mar 07, 2005 10:00 pm
Location: The North Block
Contact:

### Re: By request, server rotation bash script

This thread is pure gold, every time I need to write a 'for a in *' script in batch, this is where I start, with a copy and paste of DTR's script
If only I had the foresight to bookmark it instead of searching for it each time...

### Who is online

Users browsing this forum: No registered users and 2 guests