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
- The standard header for a bash script.
- Create the new tmux session first as daemon with the session name minecraftcontrol and execute the mcrcon command that connects to the server.
- This line binds the ESC key as a shortcut to exit the tmux session.
- Name the tmux window.
- Split the window so that two panes are side by side (horizontally).
- 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. - Select the first window again.
- 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
Robert Roslon
Maybe stupid question, but how to close tmux sessions opened by this script ?
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.