Page 1 of 1
By request, server rotation bash script
Posted: Wed Jun 22, 2005 3:07 pm
by Teppic
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.
Posted: Wed Jun 22, 2005 3:49 pm
by ducatiwannabe
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?
Posted: Wed Jun 22, 2005 4:29 pm
by ducatiwannabe
Never mind -g I got that.
Do I put this code in the conf?
Posted: Wed Jun 22, 2005 4:41 pm
by ducatiwannabe
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?
Posted: Wed Jun 22, 2005 4:44 pm
by Guest
AFAIK, its a script that will run "bzfs -conf file"... then switch it over (when, I don't know).
Posted: Wed Jun 22, 2005 4:48 pm
by ducatiwannabe
Never mind. It won't work. It's linux. DOES ANYBODY have a rotation file for Windows? I can't find one anywhere!
Posted: Wed Jun 22, 2005 4:48 pm
by Teppic
I may be able to do a batch file version for windoze later, this is a linux bash script.
Posted: Wed Jun 22, 2005 4:49 pm
by Guest
What about Mac?
No rush or anything.
But if you get some free time...
lol
Posted: Wed Jun 22, 2005 5:27 pm
by DTRemenak
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).
Posted: Wed Jun 22, 2005 6:22 pm
by 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.
Re: By request, server rotation bash script
Posted: Wed Jun 22, 2005 8:10 pm
by Teppic
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
Run the command with
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?
Posted: Thu Jun 23, 2005 5:15 am
by Sir_Pants
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
Posted: Thu Jun 23, 2005 8:38 am
by Teppic
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.
Posted: Thu Jun 23, 2005 11:01 am
by 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?
Posted: Thu Jun 23, 2005 5:59 pm
by BinarySpike
#!/bin/bash
this is correct on mac.
10.2 and above at least......
Posted: Thu Jun 23, 2005 11:04 pm
by Teppic
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.
Posted: Fri Jun 24, 2005 8:31 am
by 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?
Posted: Fri Jun 24, 2005 4:48 pm
by Teppic
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
bzadmin gameover@127.0.0.1:5154 /password=password "/say server shutting down in 20 seconds" /quit
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.
Posted: Fri Jun 24, 2005 5:47 pm
by Guest
Okay, Thanks
Thats very helpful.
Posted: Mon Jul 04, 2005 2:36 pm
by ducatiwannabe
@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?
Posted: Tue Jul 05, 2005 3:50 pm
by DTRemenak
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.
AppleScript Rotator
Posted: Tue Jul 12, 2005 5:30 pm
by Spazzy McGee
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
Posted: Mon Nov 28, 2005 4:12 am
by Molotovian
Thx for the mac code, this really helped.
Re: By request, server rotation bash script
Posted: Wed Nov 09, 2011 6:19 pm
by Teppic
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...