crigler / dtach

A simple program that emulates the detach feature of screen
GNU General Public License v2.0
492 stars 50 forks source link

Capturing STDOUT from dtach socket to a log file #18

Closed gzagatti closed 1 year ago

gzagatti commented 1 year ago

I was wondering if it's possible to capture the STDOUT from dtach socket to a log file. The idea is to capture all the session into a log file that I can analyse later.

I have tried playing with socat but could not find the correct incantation. Is that even possible?

rdebath commented 1 year ago

I'd suggest using script(1) to wrap the command inside dtach.

gzagatti commented 1 year ago

Perfect! This is what I was looking for.

For future records, I can run an ipython as:

> dtach -A /tmp/foo script -f -O foo.log -c "ipython"

All STDOUT is written to foo.log. In case I get disconnected (say from a ssh session), I can reconnect to the ipython with:

> dtach -a /tmp/foo

If the script is not interactive, I could also use nohup without dtach.

> nohup python my_script.py > foo.log &
> disown

If using script or nohup, I can follow the STDOUT with:

> tail -f foo.log