18.09.2008, 20:44
Looks Sweet. Now to try it
:SERVERSTART samp-server GOTO SERVERSTART
@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
)
!@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
$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"
|
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 |