0

I am running a Minecraft server in a GNU screen that is usually detached. What I want to do is to watch the screen and run a script every time something is printed to the screen (which the server program does quite frequently).

Is this possible? If so, how?

1

You could write a wrapper script:

#!/bin/sh
while IFS= read -r line
do
    printf '%s\n' "$line"
    # add your command/script here to be run on every new line printed
done < /dev/stdin

You can use the above script by piping the output from your program to the script

For example if above script is called ./wrapper.sh and your program is prog:

prog | ./wrapper.sh

Note that if something is printed in standard error by prog, it won't processed by the script unless you redirect it or handle stderr separately.

  • What if the command to start the server is only java -Xmx1024M -jar craftbukkit.jar -o true, can the last line of the wrapper script be done < java -Xmx1024M -jar craftbukkit.jar -o true? – tjespe Aug 19 '17 at 12:29
  • I suppose you could add your java ... command piping to while, eg. java ... | while read line ... – sebasth Aug 19 '17 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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