Ubuntu – How to save live log bash input to a file

bashcommand linelogging

When I am teaching a class, some students have problems following my CLI commands and would like to scroll back to be able to repeat the steps in their own speed. So I'd like to log all my inputs in realtime to an html-file or something similar, which I could server through a webserver. That way, the students could simply go to http://example.com/log#end and would always see the last entries.

I do know the multiuser mode of screen and have already used it to share sessions. However, I need to disable the write access of students and unfortunately, they are unable to scroll up, if I do so.

I also had a look at script, but it generates a terrible output, which – even when filtered through col -bp < logfile >> output.html is unreadable. Also, it does log the output as well, which complicates things and only dumps the logfile in unforeseeable intervals.

.bash_history could be used, but is only dumped to file when the session ends.

Any ideas?

Best Answer

Use the built-in command history:

history -w hist.txt

will save the current history into file hist.txt.

If you have write permsiions to the appropriate directory you could do something like:

history -w /var/www/html/latest_history.txt

Then your students could access it in a browser: http://teachers.ip.address/latest_history.txt