Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am working on setting up a minecraft server network in ubuntu server 14.04 LTS. I have several screen sessions each with their own process running in them

There are screens on:
    2471.LobbyServer (detached)
    2468.BungeeCordProxy (detached)

I need a way to type a single command (perhaps launching a bash script) that will loop through all of the screen sessions, and enter a command into each of the running processes (each of the processes accepts commands as input while running) depending on the jar file being used in the process (both processes are .jar files launched with Oracle java-7).

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I think you can run:

screen -S panel -p 0 -X stuff "yourCommand`echo -ne '\015'`"

The -p is the window number and the echo part inserts a newline at the end

share|improve this answer
    
Is there some way to loop through and execute a different command depending on what jar file is running? –  john01dav May 7 at 7:15
    
Ouch! That's a big ask. I think I might look for a different answer than stuffing text into the console in that case. At least, if you should try to have each jar type in a specific named screen session so you know in advance which command to send. If not, I think you need to look for a more sophisticated way of communicating with the jar apps. –  Julian Knight May 7 at 22:44
    
Yep, that's why I asked it here (there are lots of smart people here). I can add code to the jar apps fairly easily, but the problem is that how could I have the code communicate with the rest of the system (the best I can think of is having a file that is read over and over by the java app, and when it sees a certian code (perhaps "stop") it just stops, I already, which seems pretty inefficient).? –  john01dav May 8 at 21:46
    
You are thinking along the same lines as me. File system access is very efficient on UNIX like systems. I'd add a file-system monitor to the Java app and when the file system triggers a new file event on the watched folder, trigger a sub-routine to read and delete the file, parse the content for known commands and execute accordingly. You are really implementing a message bus in miniature. A useful bit of function. I've done similar but monitoring IMAP mail folders in the past (with PHP rather than Java). –  Julian Knight May 9 at 11:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.