0

I'm trying to capture the log output of a piece of software running in server mode on localhost in the bash script that triggers the communication with the server via nc.

The server is started like this:

java -Xms4g -Xmx6g -jar target/Semafor-3.0-alpha-04.jar model-dir:../semafor_malt_model_20121129 port:4444

The communication from the bash script is:

cat file | nc localhost 4444 > ./output

This captures the STDERR output as is the case with nc nicely.

But I can see lots of log messages scrolling through in the terminal window where I started the server, and my question is how I can capture these messages in the bash script (and thus save them under a specific filename file.log, which would be different for each file sent)?

I've tried various suggestions, like capturing the output from the bash command in a variable

var=$(cat file | nc localhost 4444 > ./output)

or even trying to capture the terminal output with script but without any success. I'm clearly out of my depth here, and any pointers would be gratefully received.

1 Answers1

0

I think you could use screen:

screen -S session_name -L -X eval 'java...'

-L flag will generate a log with all the stuff you require on the current directory.

Regards,

  • Thanks for the suggestion. Screen is new to me and I seem to be running into errors about java and path components not being found. Will have a proper go at it tonight, and may have more relevant questions then. – Alexander Huber Apr 11 '16 at 15:15
  • Sorry, I'm struggling to get this to work. All classpath and other path information seems to get lost when using screen, is there a way around this? I've tried replacing relative with absolute paths, but some are defined in ENV variables that I cannot change easily. Any ideas? – Alexander Huber Apr 11 '16 at 22:34
  • There are several ways to get that problem solved, but the easiest way is to use setenv command, you may find more information [here](http://unix.stackexchange.com/questions/157202/how-to-set-screen-environment-variable-from-bash). – antonioalopezfernandez Apr 12 '16 at 09:42