I want to make a shell script which copies the past outputs of the GUI terminal emulator (for example, last 20 lines). The motivation is as following:
When I execute a procedure which requires long time (for example, downloading a very large file, or converting a very large movie file), I sometimes remember another job, and I have to leave the room. In such a case, I press ctrl+z to stop the procedure. And I type
fg; echo $? >> log.txt; date >> log.txt; systemctl poweroff
then I leave the room.
This way works and is not bad. But it has a disadvantage that I cannot read the outputs of the procedure. I can know only the status ($?). So I want to copy last 20 or 40 lines and save them in log file.
tee
to redirect to a file AND to stdout). Alternatively, depending on which window manager you use, you could use a screenshotting tool - most allow you to screenshot a particular window rather than the entire screen. e.g.xfce4-screenshooter
's-w
option takes a shot of the currently active window (if necessary, you could use wmctrl or similar to select which window is active). Finallytmux
has asave-buffer
option to save the current buffer to a file. – cas Apr 11 '22 at 05:55