Re: SA-MP Server Log Rotation -
Acoole - 18.09.2008
Looks Sweet. Now to try it
Re: SA-MP Server Log Rotation -
-Sneaky- - 02.01.2009
Allright, so I was searching for a automatic server restarter, done some research in batch programming lol, first
KingJ came up with this:
Code:
:SERVERSTART
samp-server
GOTO SERVERSTART
This will restart the server if you EXIT it, but then I thought what if someone puts 'gamemode0 asd 1' but asd.amx isn't in the gamemodes directory.. so I tested it and the server restarted a thousand time and filled up the server_log.txt really fast :X
So uhm yeah I did some more research on ******, find some time/date functions & used KingJ rotation script, modified it and came up with this:
pawn Code:
@ECHO OFF&SETLOCAL
FOR /f "tokens=1-4 delims=/-. " %%G IN ('date /t') DO (call :S_FIXDATE %%G %%H %%I %%J)
:S_FIXDATE (
if "%1:~0,1%" GTR "9" shift
FOR /f "skip=1 tokens=2-4 delims=(-)" %%G IN ('echo.^|date') DO (set %%G=%1&set %%H=%2&set %%I=%3)
)
FOR /f "tokens=*" %%G IN ('time/t') DO set _time=%%G
SET _time=%_time:~0,2%-%_time:~3,2%
ENDLOCAL&SET _time=%_time%
SET delay=20 // 1 = 1 second - set the delay of a server restart after a rcon exit
SET ServerDirectory="C:\Path\To\Your\Server" // set this to the path to your server
SET title=My First SA-MP Server :) // set the title of your server
TITLE %title%
ECHO -
ECHO Server Restarter & Log Rotation - By Sneaky
ECHO -
:SERVER_FIRST_START (
samp-server
GOTO SERVER_START
)
:SERVER_START (
ECHO Restarting server with a delay of %delay% seconds...
ECHO Renaming log file to log_%dd%-%mm%-%yy%-%_time%.txt...
RENAME %ServerDirectory%\server_log.txt log_%dd%-%mm%-%yy%-%_time%.txt
ECHO Moving log to logs folder...
MOVE %ServerDirectory%\log_%dd%-%mm%-%yy%-%_time%.txt %ServerDirectory%\logs
ECHO Succes!
PING -n %delay% 127.0.0.1 >nul
samp-server
GOTO SERVER_START
)
This will restart the server
~20 seconds after rcon exit is used and creates a log file with date/time in a folder called 'logs' in your server directory.. I tested it and it works all fine, dont know if this is the best way or if it's usefull for anyone but yeah anyways..
Setup:
1. Copy code above
2. Open notepad > paste it in
3. Change SET ServerDirectory="C:\Path\To\Your\Server"
4. Optional you can change the delay time and title of the server
5. Save as startserver.bat
6. Start up startserver.bat instead of samp-server.exe
7. Dont forget to create a folder called 'logs' inside your server directory!
Re: SA-MP Server Log Rotation -
LethaL - 02.01.2009
Sneaky your code uses the time and date from when the .bat file was first run, so the logs keep getting over written on every restart.
Re: SA-MP Server Log Rotation -
-Sneaky- - 02.01.2009
You sure? Cause I tested it and it uses the current time and not the time when the .bat file was first run everytime.. ;X
Re: SA-MP Server Log Rotation -
kingdutch - 25.03.2009
Ok so I've skimmed through the topic.
And I've read things like the server recreates a log file automatically and that it doesn't.
If it doesn't, can't you just touch "server_log.txt"? And you got your problem solved, no reason for the server to restart.
BTW I always tarred my logs to reduce filesize and then transferred them to an apache server (Or FTP Folder in some other peoples cases) so I could download them from my main computer. If anyone wants that script just reply, it's quite simple. (Just tars the file to my webserver and then rm's the server_log.txt)
SA MP Server Log Rotation -
CipHoony - 22.07.2009
For our versus server it seems anytime I try and just jump in the server my search key will not work, everytime I restart the server before going in game it works. Does anyone know if there is a mod or script so that after the server has people in it then goes empty it automaticly restarts?
Thanks guys
Re: SA-MP Server Log Rotation -
Westie - 02.08.2009
I can. Muhahaha.
Re: SA-MP Server Log Rotation -
Machinehank34 - 11.08.2009
Confusing.... But cool

!
Greetz,
Machine.
Re: SA-MP Server Log Rotation -
Patrik356b - 25.08.2009
I made an edit, with this improvement, you dont need to specify the path, just remember to put it in your server folder
Code:
@echo off
Set ServerDirectory=%CD%
set ServerName="samp-server.exe"
for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set XDate=%%a-%%b-%%c
if not exist %ServerDirectory%\log mkdir %ServerDirectory%\log
echo Daily log rotator for SA-MP Servers by KingJ
echo Will rename the current log file to today's date (%DATE%)
echo and place it in the log folder.
echo.
echo Path to use:
echo %CD%
echo.
echo Ensure the server is not running.
echo.
echo This makes the server logs easier to manage
echo.
echo Stopping server...
taskkill /f /im "%ServerName%"
echo Renaming log file to server_log_%XDate%.txt
rename %ServerDirectory%\server_log.txt server_log_%XDate%.txt
echo Moving log to log folder...
move %ServerDirectory%\server_log_%XDate%.txt %ServerDirectory%\log
echo Starting Server...
start %ServerDirectory%\%ServerName%
echo.
echo Log rotation complete
Re: SA-MP Server Log Rotation -
shady91 - 08.10.2009
x-serverz has had this for ages as i said to tommis once were's my log file's, as when ever you reset your server it auto puts log in a folder and then makes a new one, but before he told me how it worked i wasn't sure were my log files were going lol then i opened me log folder it had about 2000 files lol.
Re: SA-MP Server Log Rotation -
DeltaAirlines12 - 21.10.2009
XD, I should make a .bat that sends my log automatically go into my recycling bin
SA MP Server Log Rotation -
brubsifiary - 28.12.2009
I have configures the conf file, but now what I need to do ?
Many thanks for your help
Re: SA-MP Server Log Rotation -
Domenko - 19.02.2010
Yep i agree!
Re: SA-MP Server Log Rotation -
Westie - 20.02.2010
Above two posters - wait what?
Re: SA-MP Server Log Rotation -
Westie - 10.03.2010
Awesomeness double post, I was sorting through my NAS when I came across this. Points given to those who know what this is:
Code:
$directory = "C:\path\to\sa-mp\server\"
$serverlog = "server_log.txt"
if((Test-Path -path "$directory\logs\") -ne $True)
{
New-Item "$directory\logs\" -type directory
echo "A new log directory has been created."
}
$timestamp = (date -uFormat %s)
$thedate = (date)
cat "$directory\$serverlog" | out-File -encoding ascii "$directory\logs\server.$timestamp.txt"
echo "Refreshed at $thedate" | out-File -encoding ascii "$directory\$serverlog"
Re: SA-MP Server Log Rotation -
viKKmaN - 10.03.2010
Is there a way to delete the server_log when the server closes? Or to disable the log feature?
I kinda hate the server_log.txt beeing put in my main server folder, and i'd like to use my own logging feature? Is it possible to disable it?
Re: SA-MP Server Log Rotation - Micko9 - 22.03.2010
OOOOOOOOOOH CRAP! my log is 1.91 MB ...sigh... oh well il delete it . But usefull .
Re: SA-MP Server Log Rotation -
JernejL - 23.03.2011
Quote:
Originally Posted by kaisersouse
NotE:
if you remove server_log.txt while the server is running...it will not automatcially recreate it.
You must stop the server
run the log rotation scrpt
restart the server
|
Use this to empty / blank the old log instead of removing it so the server will keep on logging:
Step 1: Copy the log contents to a new file with "cat server_log > otherlog/today.txt"
Step 2: Overwrite the server_log stream with null data by using "echo > server_log.txt" - this will blank the log file and server will continue appending new data to it.
This is tested and works fine on linux.
Re: SA-MP Server Log Rotation -
rapidhost - 04.12.2011
Quote:
Originally Posted by Westingham
For those admin who use this log rotation .bat, how do you make sure all data is saved before the server goes down?
|
good job on a 10 month old bump ..
Your stuff doesnt get lost.. just make it autosave with a timer function in ur script .......
Re : SA-MP Server Log Rotation -
ombre - 16.10.2012
where to put the logrotate.sh ?
thanks