How can I save the output of a detached screen with script?
You can use the -L
flag to create an automatic screenlog.0
file
eg
$ screen -dm -L sh -c 'echo hello'
$ cat screenlog.0
hello
If you have a long running screen session that isn't being logged then you can turn on logging later
eg
$ screen -dm -S test sh -c 'while [ 1 ]; do date; sleep 1; done'
Now we can turn on logging
$ screen -S test -p 0 -X log
Allow some time to pass, because the logging is written in blocks, and...
$ cat screenlog.0
Fri Aug 26 13:25:49 EDT 2016
Fri Aug 26 13:25:50 EDT 2016
Fri Aug 26 13:25:51 EDT 2016
Fri Aug 26 13:25:52 EDT 2016
Fri Aug 26 13:25:53 EDT 2016
Fri Aug 26 13:25:54 EDT 2016
Fri Aug 26 13:25:55 EDT 2016
Fri Aug 26 13:25:56 EDT 2016
Fri Aug 26 13:25:57 EDT 2016
Fri Aug 26 13:25:58 EDT 2016
You should do it the other way round, run script
inside screen
:
screen -dm bash -c 'script -c "python test.py" output.txt'