LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-20-2015, 07:49 AM   #1
Rooksu
LQ Newbie
 
Registered: Mar 2015
Posts: 5

Rep: Reputation: Disabled
Bash shell issuing commands to the process it starts


Hello!

I have a shell script to start Minecraft. It works great, but I want to be able to send commands to Minecraft from the shell script. For example:

Code:
#!/bin/sh

java -Xms512M -Xmx4096M -XX:MaxPermSize=256M -jar minecraft_server.1.8.7.jar
sleep 10
echo "say This is a test.\r"
The java process starts, but it never gets to the echo. Is there a way to accomplish this? Do I need to start a second script and grab the PID of the java process? Something to do with screens? I've tried a few different things but can't for the life of me figure out where to go from here.
 
Old 07-20-2015, 08:05 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
you can background the first command like this:
Code:
#!/bin/sh

java -Xms512M -Xmx4096M -XX:MaxPermSize=256M -jar minecraft_server.1.8.7.jar &
sleep 10
echo "say This is a test.\r"
but not sure if the minecraft server is written to take commands in that fashion.
 
Old 07-20-2015, 10:10 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,881
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Do you know how to send commands to Minecraft? Or that Minecraft would be listening or capable of accepting messages?

The echo would work once you put java in the background as shown, but I don't know whether or not the Minecraft game itself would accept messages if the intent is to send external messages into that applet.
 
Old 07-20-2015, 09:06 PM   #4
Rooksu
LQ Newbie
 
Registered: Mar 2015
Posts: 5

Original Poster
Rep: Reputation: Disabled
I know Minecraft can accept commands from shell. Here's a github repo of a web interface that uses shell to issue Minecraft commands: https://github.com/Thue/rfwadmin

I'm trying to dissect it right now. The separate threading with & worked, but as you pointed out the echo wasn't accepted by Minecraft.
 
Old 07-20-2015, 11:12 PM   #5
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by Rooksu View Post
I know Minecraft can accept commands from shell. Here's a github repo of a web interface that uses shell to issue Minecraft commands: https://github.com/Thue/rfwadmin

I'm trying to dissect it right now. The separate threading with & worked, but as you pointed out the echo wasn't accepted by Minecraft.
The echo goes to the standard output of your shell script. Since minecraft is not reading from the standard output, it doesn't receive the echo.

minecraft might read from some IO channel. You have to find out what that channel is. Next step figuring out how to write to it.
 
Old 07-21-2015, 07:17 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,881
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Actually echo might be exactly what would work for you. For instance if you wished to send a character over a serial connection, such as /dev/ttyS0, you could choose to do:
Code:
echo "hi there" > /dev/ttyS0
and then this would be sent out via that serial connection. Therefore if there were a named pipe where Minecraft accepts these commands, echo and the output redirector would do the job. Similarly there are things like /proc or /sys resource files where if you need to change a setting, the resource is read-only. Something like the CPU speed adjust, stuff like that. You would echo a ONE or a ZERO to the file, but not be able to read it back, however it would institute a change in the controls of the system.
 
Old 07-22-2015, 06:06 AM   #7
Rooksu
LQ Newbie
 
Registered: Mar 2015
Posts: 5

Original Poster
Rep: Reputation: Disabled
Turns out I was making this harder than it needs to be. Minecraft implemented rcon, so I can communicate with the server without a shell script: https://github.com/thedudeguy/PHP-Minecraft-Rcon

In case someone finds this thread on Google and really does want to use shell scripting, I also got shell working with tmux. If you start the server using tmux (tmux new -a minecraft), you can control it with a shell script like this:
Code:
#!/bin/bash
tmux send-keys -t minecraft "say Hello World!" Enter
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding additional commands to a bash shell script iwitham Linux - Newbie 6 10-12-2011 07:49 AM
How to process billions of small files using Bash shell commands with limited memory? Osirix Linux - Newbie 1 05-26-2010 10:07 PM
Shell Script : Kill a running process when another process starts ashmew2 Linux - General 3 08-20-2008 03:47 AM
Issuing commands from c++ program to the shell cyberfox007 Programming 7 02-03-2008 04:06 AM
Issuing Telnet commands via bash scripts Kaj Programming 2 01-02-2005 11:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration