Search code examples
loggingscreenstdoutstderr

Log stdout & stderr when program is started in screen


I successfully added logging for the stdout/stderr of a program output to a file.

But when I start the program from screen the logfile is empty, because it only logs messages from screen and not from the program running in the background within screen.

Any way to fix this or other solutions please, so I can run a detachable program with stdout/stderr logging, similar to screen?

current startup line:

screen -A -m -d -S test ./testserver -config=config.cfg -filepatching -autoinit 1>>"./log_$(date +%s).txt" 2>>"./log_$(date +%s).txt"


Solution

  • The problem is, that you need to encapsulate your command. Right now 1>>"./log_$(date +%s).txt" 2>>"./log_$(date +%s).txt" applies to screen itself, nit the program executed.

    Try this instead:

    screen -A -m -d -S test './testserver -config=config.cfg -filepatching -autoinit 1>>"./log_$(date +%s).txt" 2>>"./log_$(date +%s).txt"'
    

    Or this:

    screen -A -m -d -S test /bin/sh -c './testserver -config=config.cfg -filepatching -autoinit 1>>"./log_$(date +%s).txt" 2>>"./log_$(date +%s).txt"'