Minecraft rcon tool for Linux Console

minecraft-java-edition

I am searching for a Linux commandline tool to use the rcon to send Command to the minecraft server.

While I found one in the Minecraft Forum it does not work as expected, most time the Auth Succeeds but the Command does not get executed and the programm quit in reading the results from the Server

Any hints for a working program, or how to fix the mentioned one?

Best Answer

I'm assuming you're running minecraft in a screen session, since it's the most convenient way to not force you to keep an ssh connection always open.

You can send a command to screen that it forwards to the application running inside it. For example, I am running it in a screen session called minecraft, and every few hours a script runs, forces a save, toggles autosave off, does a backup of my worlds files, then turns autosave back on.

This is how you start a new screen session called minecraft:

screen -S minecraft

then you get a shell, you may also pass the command you want to run automatically instead of getting a shell.

Then you can send commands to that session:

screen -p 0 -S minecraft -X eval "stuff save-all\015"
  • -p 0 sends the message to window 0 in the session
  • -S minecraft is the session name
  • the rest tells to print "save-all" and a newline to the application's stdin