« User Environment | Main | Sudoscript 2.1.2 beta 1 Released »

June 06, 2004

Displaying script(1) Logs

In my sudoscript entry in BSD Hacks, I discuss the possibility of snipping a vi session out of sudoscript log and cating it to the screen to visualize it. This only works if you use the same terminal emulator as the sudoscript user, and if your terminal is sized the same. I reread the entry when the book came out recenty, and it piqued my interest in developing software to make the process easier. My first crack at a script to list and replay sudoscript sessions is here. The script has several weaknesses, most stemming from the fact that it's just a quick hack. For example, there's no spanning of log files, and if the session you are interested in is not in the file you choose, then you won't see it at all. One drawback that can't be hacked around though is the coarse (1s) resolution of the timestamps in the sudoscript logs, and the fact that even those timestamps reflect when the line-blocked output hit the logging daemon, not when the character-blocked output occurred in script(1). Even so, the script is useful, as long as your terminal emulator and settings match the user's.

Digging into the timing issue, I flirted with using Time::HiRes to write better logs. But the line blocking is still unavoidable. Also, I hate to make my portable code depend on modules that aren't in the Perl standard library (Time::HiRes was added in 5.8.0). Speaking of unportable solutions, the script(1) that comes with util-linux has this nifty feature:

  -t      Output timeing data to standard error. This data contains 
          two fields, separated by a space. The first field indicates 
          how much time elapsed since the previous output. The second 
          field indicates how many characters were output this time. 
          This information can be used to replay typescripts with 
          realistic typing and output delays.

This is cool! The script program is in the best position to know exactly when characters were typed and displayed. On Linux, script helpfuly provides this information. A script to replay sessions from a typescript and timing files is here. Run linux script(1) like this:

   script -f -t 2>times

Do some fullscreen stuff. Run vi, top or whatever. Exit script and run replay in the same directory. It works really well!

Integrating this into sudoscript would be tough. If ss finds it is running on Linux, it would have to redirect script's stderr as above to a per-session timings file. Later, an adapted replay script could snip the sessions out of the log files and write them to a temporarily reconstituted typescript. This would have to be exactly like what would have been written if the output hadn't gone to the daemon. (Of course, I could just write the typescript directly, but the daemons do a fair amount of useful work besides writing the logs.) Managing these files would be interesting. When a log drops off the end of the rotation, the corresponding timings file(s) should be deleted to.

Add in the unportability of this approah, and I'm more inclined to go with the less than perfect, but perhaps good enough first solution.

Update: The script from util-linux builds and runs on OpenBSD. The portability issue is only with systems that use SysV PTYs. At least, the build honks loudly on Solaris 9. I assume that HP-UX, AIX and Irix would have similar problems. If four of the platforms I support can run this modified script(1), then I'm somewhst more willing to look at implementing it.

Posted by hbo at June 6, 2004 12:53 PM


Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Remember me?