Leave remote command running storing output

gnu-screenoutput

Scenario;

I have SSH'ed to a machine, opened a new screen session, and fired off a script.

Some days later I SSH back to that machine, re-attach the screen session and look at the output that has been generated, however; I can't scroll back through the output.

From what I can see, screen stores one "screens worth" of stdout output. If my script has generated 100 lines of output in 48 hours, I can't see it all, just the last 40 odd lines or so. Is there a way to make screen store all stdout from the script I leave running, so I can re-attach the screen and PgUp/PgDn through it as if it were a script running on my local machine?

Perhaps screen isn't the most optimal way to do this? Is there a better method for leaving scripts running on remote machines after log out, and being able to re-attach to that process at a later date and view all the output?

Best Answer

Screen does keep a log of past output lines; it's called the “scrollback history buffer” in the Screen documentation.

To navigate through the scrollback, press C-a ESC (copy). You can use the arrow and PgUp/PgDn keys to navigate, as well as other keys to search and copy text. Press ESC to exit scrollback/copy mode.

By default, Screen only keeps 100 lines' worth. Put a defscrollback directive in your .screenrc to change this figure.

If you want a complete log from your script, save it in a file. Run it inside Screen to be able to connect back to the parent shell and easily see if the script is still running, suspend and restart it, etc. Or fork it off with nohup. To monitor the log file while it's growing, use tail -f.

Related Question