Need script autostart in batch mode for minecraft server

I am currently an administrator on a private Minecraft server, although in this case the technical question is outside the scope of a typical minecraft supoort.

I want to have a batch file that triggers a server restart at 12:00 and 12:00, although I have little experience in batch mode and a cursory google search does nothing.

The problem I am running into is that I have no idea if the command line can run commands in the Java server console, send commands to save the server, and then shutdown and restart themselves due to the fact that they only know basic package functions.

Specifically, I want the batch file to run the command itself in the server window after 43200 seconds, or on each of the 12, and then restart itself. I don't know how to get the batch file to run the command on the server command line, or if possible.

The current batch code looks like this:

@echo off
:Minecraft
echo (%time%) Minecraft started.
java -Xms2048m -Xmx2048m -XX:PermSize=128m -jar FTBServer-1.6.4-965.jar nogui
pause
echo (%time%) WARNING: Minecraft closed or crashed, restarting.
ping 1.1.1.1 -n 1 -w 3000 >nul
goto Minecraft

      

Any help would be appreciated. Thank.

+3


source to share


3 answers


I use this, but if you want it to restart it automatically, just remove the: choise part and do a loop from start to restart.



@echo off
title minecraft-server-1.8.3
color 0A
prompt [server]:
cls

:start
echo loading server...
java -Xms3G -Xmx3G -jar minecraft_server.1.8.3.jar nogui
cls

:choice
set /P a=do you want to restart[Y/N]?
if /I "%a%" EQU "Y" goto :restart
if /I "%a%" EQU "N" goto :stop
goto :choice


:restart
cls
echo server will restart
TIMEOUT /T 5
cls
goto :start

:stop

cls
echo closing server
TIMEOUT /T 5
exit
      

Run codeHide result


ps. replace minecraft_server.1.8.3.jar file with your server filename

+2


source


Solution 1: I would suggest using Windows Task Scheduler instead of a batch file. There you can create a task, schedule it to run at 12am / hour, and paste in whatever cmd command you want to execute. However, it is non-trivial to work with the server console without knowing the specific interface or how to manage the minecraft server. You can just kill the server and restart it using the command line.

Solution 2: If you don't like this solution and don't know how to contact the server console, you can try this: Take a look at AutoIt ( https://www.autoitscript.com/site/ ). It is a very simple script language that can simulate clicking and keyboard input as well. Thus, you can write a script that sets focus to the server console and enters the desired command to restart the server. This AutoIt script can be compiled into an exe file or you can run it as an au3 script. You should still use the task scheduler to run the exe / script at 12am / hour.



If you need help writing an AutoIt script, I can help you with that.

+1


source


I wrote a similar program for a friend in AutoIt, here is the script I have commented out the lines you need for config:

HotKeySet("{ESC}", end)
HotKeySet("{F1}", start) ;optional
HotKeySet("{F2}", pause) ;optional

pause() ; starts the pause loop when started

; restarts the server all 12 hours
Func start()
    $Path = "PathToYourBatch.bat" ; self explained

    While 1
        If @HOUR =  00 Or @HOUR = 12 Then ;starts the server at 00 and 12 
            Run($Path)
        EndIf
    WEnd
EndFunc

Func pause()
    While 1
        Sleep(500) ; waits 500 ms to reduce lag
    WEnd
EndFunc

Func end()
    Exit
EndFunc

      

You don't need to use hotkeys, but you can easily control the program with them (remote desktop)

You can use the online compiler ( http://www.script-example.com/themen/AutoIT-Online-Compiler.php ) or download it from ( https://www.autoitscript.com/site/ ) hopefully can help if any further code questions ask me.

0


source







All Articles