1

So I have a Minecraft server on my spare system. It runs 24/7 but as I plan to get more servers I and other system I want a way for when the UPS goes to battery mode it will trigger a script which if the power stays off long enough . Now I have the shutdown.sh already made and kinda know how the get the script to execute another I just need warn the players on the server. Now my server is java based and runs through the terminal and my issue is that I can't seem to find a way to push commands to the server like -/say server shutting down in 1 minute -

Now I have a program already that can trigger the script I need for when the server shuts down and stuff I just need help pushing and executing the commands on the server terminal.

in short i need a way for a script to execute commands in an active terminal

And before anyone says anything I already have a startup script

Here is the flow of the scripts I'm planning

script 1 general power failure steps

  1. after 30 seconds of power loss

  2. Will say msg on server with a 4 minute timer

  3. after 2:30 minutes will say its doing a preemptive save

  4. if all good till end of time

  5. at the end of 4 minutes the sever software will receive a stop command and 10-30 seconds later a full system shutdown

script 2 power fail and low ups battery

X1. if ups battery starts reaching a certain percent like 30%

X2. will immediately force step 3. along with server msg saying reading low battery early immediate shutdown in progress

X3. well enforce step 5 immediately regardless of how much time is left

  • i need a way for a script to execute commands in an active terminal – shiva chirr Jun 29 '20 at 21:45
  • i feel like you miss understood. i need a the scrpit to run commands in a server terminal not its own. so if term a is the server and term b is the one running the script. the script will send commands to term a like a shutdown command to the server. but in this case the script will be auto run via a program in the background – shiva chirr Jun 29 '20 at 21:53
  • Do you mean like in the answer here: https://askubuntu.com/questions/641683/how-can-i-send-commands-to-specific-terminal-windows – Mark Kirby Jun 29 '20 at 21:57
  • kinda but in the end the script will be running in the background when the ups monitor detects power issues. and it will be sending commands to a terminal that is running a mincraft server. so i do not think thats what i want. – shiva chirr Jun 29 '20 at 22:03
  • Does the "Minecraft server" open a socket for command input? Does it handle signals (man kill)? – waltinator Jun 30 '20 at 02:10
  • 1
    You can run tmux session and keep it open (attached) in the active terminal where you run your commands... Also you will be able to send commands to this session via scripts and other terminals. Here is how to begin: https://askubuntu.com/a/1027879/566421 – pa4080 Jun 30 '20 at 07:10
  • You can try if "expect" (https://linux.die.net/man/1/expect ) is able to do what you want. I have used expect a lot, but I never used it to connect to an already running terminal and don't know if it's able to do it (typical expect usage scenario is open a session eg. via ssh from inside an expect script and then send commands). If yes, then certainly you can achieve your goal with expect. – raj Jun 30 '20 at 10:28

0 Answers0