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
Post Reply
User avatar
Teppic
Private First Class
Private First Class
Posts: 575
Joined: Mon Mar 07, 2005 10:00 pm
Location: The North Block
Contact:

By request, server rotation bash script

Post by Teppic » Wed Jun 22, 2005 3:07 pm

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.

User avatar
ducatiwannabe
Private First Class
Private First Class
Posts: 3249
Joined: Tue Aug 10, 2004 3:55 pm
Location: Planet Earth
Contact:

Post by ducatiwannabe » Wed Jun 22, 2005 3:49 pm

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?

User avatar
ducatiwannabe
Private First Class
Private First Class
Posts: 3249
Joined: Tue Aug 10, 2004 3:55 pm
Location: Planet Earth
Contact:

Post by ducatiwannabe » Wed Jun 22, 2005 4:29 pm

Never mind -g I got that.

Do I put this code in the conf?

User avatar
ducatiwannabe
Private First Class
Private First Class
Posts: 3249
Joined: Tue Aug 10, 2004 3:55 pm
Location: Planet Earth
Contact:

Post by ducatiwannabe » Wed Jun 22, 2005 4:41 pm

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

Post by Guest » Wed Jun 22, 2005 4:44 pm

AFAIK, its a script that will run "bzfs -conf file"... then switch it over (when, I don't know).

User avatar
ducatiwannabe
Private First Class
Private First Class
Posts: 3249
Joined: Tue Aug 10, 2004 3:55 pm
Location: Planet Earth
Contact:

Post by ducatiwannabe » Wed Jun 22, 2005 4:48 pm

Never mind. It won't work. It's linux. DOES ANYBODY have a rotation file for Windows? I can't find one anywhere!

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

Post by Teppic » Wed Jun 22, 2005 4:48 pm

I may be able to do a batch file version for windoze later, this is a linux bash script.

Guest

Post by Guest » Wed Jun 22, 2005 4:49 pm

What about Mac?
No rush or anything.
But if you get some free time... :wink: lol

User avatar
DTRemenak
General
General
Posts: 625
Joined: Thu Jan 16, 2003 4:54 am
Location: U.S.
Contact:

Post by DTRemenak » Wed Jun 22, 2005 5:27 pm

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

Post by Guest » Wed Jun 22, 2005 6:22 pm

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. ;)

User avatar
Teppic
Private First Class
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

Post by Teppic » Wed Jun 22, 2005 8:10 pm

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
Private First Class
Posts: 194
Joined: Mon Mar 28, 2005 2:41 am
Location: SOMEwhere in WA

Post by Sir_Pants » Thu Jun 23, 2005 5:15 am

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
Image

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

Post by Teppic » Thu Jun 23, 2005 8:38 am

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

Post by Guest » Thu Jun 23, 2005 11:01 am

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?

User avatar
BinarySpike
Corporal
Corporal
Posts: 735
Joined: Mon Mar 28, 2005 11:58 pm
Contact:

Post by BinarySpike » Thu Jun 23, 2005 5:59 pm

#!/bin/bash
this is correct on mac.
10.2 and above at least......

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

Post by Teppic » Thu Jun 23, 2005 11:04 pm

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

Post by Guest » Fri Jun 24, 2005 8:31 am

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?

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

Post by Teppic » Fri Jun 24, 2005 4:48 pm

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.

Guest

Post by Guest » Fri Jun 24, 2005 5:47 pm

Okay, Thanks :) Thats very helpful. 8)

User avatar
ducatiwannabe
Private First Class
Private First Class
Posts: 3249
Joined: Tue Aug 10, 2004 3:55 pm
Location: Planet Earth
Contact:

Post by ducatiwannabe » Mon Jul 04, 2005 2:36 pm

@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?

User avatar
DTRemenak
General
General
Posts: 625
Joined: Thu Jan 16, 2003 4:54 am
Location: U.S.
Contact:

Post by DTRemenak » Tue Jul 05, 2005 3:50 pm

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.

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

AppleScript Rotator

Post by Spazzy McGee » Tue Jul 12, 2005 5:30 pm

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

User avatar
Molotovian
Private First Class
Private First Class
Posts: 52
Joined: Mon Oct 31, 2005 4:27 am
Location: Sniper's Nest

Post by Molotovian » Mon Nov 28, 2005 4:12 am

Thx for the mac code, this really helped.
,/../,('_') Molotovian ('_'),\..\,

User avatar
Teppic
Private First Class
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

Post by Teppic » Wed Nov 09, 2011 6:19 pm

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...

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests