The Header: Enauts Thinking!
created:Fri 29 May 2015
edited:Thu 01 Aug 2019
translations: english no translations

Minecraft Server Command Center Script

When the server is set up with systemd and rcon it is still quite cumbersome to connect to the command promt.

To get a nice and slick command center I created a bash script that opens up a tmux session with two panes. The first pane contains the the already logged in command promt of the minecraftserver and the second pane contains the last 40 journal entries and updates live if anything new is coming.

So for the impatient here is the script:

minecraftcontrol.sh

#!/bin/sh
tmux new-session -d -s minecraftcontrol '/var/minecraft/mcrcon -H localhost -P $port -p $password -t'
tmux bind-key -n Escape kill-session
tmux rename-window 'Minecraft Control Center'
tmux split-window -h
tmux send-keys 'journalctl -f -u minecraft -o cat -n 40' 'C-M'
tmux select-pane -l
tmux -2 attach-session -t minecraftcontrol

Line by Line Explanation

  1. The standard header for a bash script.
  2. Create the new tmux session first as daemon with the session name minecraftcontrol and execute the mcrcon command that connects to the server.
  3. This line binds the ESC key as a shortcut to exit the tmux session.
  4. Name the tmux window.
  5. Split the window so that two panes are side by side (horizontally).
  6. In the second pane display the last 40 log entries of systemd.service minecraft. Display the messages the cat format meaning without any timestamps only the messages that came from the server. The -f option is responsible for the updates whenever a new log entry appears.
  7. Select the first window again.
  8. Attach to the session.

Usage

To start the "Command Center" just execute the script. On the left side you can enter whatever minecraft command you wish to execute. On the right you can see all the recent log entries. you can use the ESC key to exit the whole thing or use any tmux command you like.

Comments

created:Mon 19 Feb 2018
edited:Mon 19 Feb 2018

Robert Roslon

Maybe stupid question, but how to close tmux sessions opened by this script ?

created:Mon 19 Feb 2018
edited:Mon 19 Feb 2018

enaut

@ Robert Roslon

just press the [ESC]-key or use any tmux command from: https://tmuxcheatsheet.com/ or anywhere you like

Add a new comment

Note that all comments are moderated - so your post will not appear till I find time to accept it.

The comments do use markup syntax.

Name:
Email:
Confirm Email: leave the above line empty!
Comment: