diff --git a/README.md b/README.md index deea5ed..a22ba70 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,117 @@ scriptreplay_ng =============== + +Installation +------------- + + * Install "scriptreplay" and "recordsession" to /usr/local/sbin + * Add /usr/local/sbin to $PATH of the user + * Add the follwing lines via "visudo" + ``` + ALL=NOPASSWD: /usr/local/sbin/scriptreplay + ALL=NOPASSWD: /usr/local/sbin/recordsession + ``` + + +Usage +----- + + * Start session + ``` + sudo recordsession + ``` + * Replay session + ``` + sudo scriptreplay -t /var/log/recordshell//2013-07-08/2013-07-08_17-39-41-27336/timing.gz /var/log/recordshell//2013-07-08/2013-07-08_17-39-41-27336/typescript.gz + ``` + +Documentation +------------- + +``` +NAME + scriptreplay - play back typescript of terminal session + +SYNOPSIS + scriptreplay -h|--help + + scriptreplay [-a|--accelerate ] [-t|--timing ] + + +DESCRIPTION + scriptreplay replays a typescript of a terminal session; optionally, + using timing data to ensure realistic typing and output delays. + + The timing data consists of 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. + + *typescript* is the path to the typescript file. If the file + *typescript*.timing exists then it is automatically used as timing data + file. Use parameter -t or --timing to specify an alternative timing data + file. + + This version of scriptreplay supports reading of compressed *typescript* + files. If *timingfile* is not specified, scriptreplay tries to open a + timing data file that uses the same compression algorithm as + *typescript*. The decompression method is determined by examining the + file extension of the *typescript* file. Recognized file extensions of + compressed *typescript* files are: "bz2", "gz", "lz" or "lzma". + + Controlling the playback + * "-" or "d" decreases display speed. + + * "+" or "i" increases display speed. + + * "s" or "p" pauses the playback; and "c" continues again. + + * "f" or "q" stops the playback and exits scriptreplay. + + Pressing any other key jumps to the next output (useful if there is no + output activity due to a long delay). + +OPTIONS + -a, --accelerate *num* + Accelerates timing by factor *num*. *num* must be greater than + 0. A *num* value less than 1 slows down the playback speed; and + a value greater than 1 increases the playback speed. + + -t, --timing *timingfile* + Specify the file path to the timing data file. + +EXAMPLES + Create a new typescript with timing data + user@caladan:~$ script -t typescript 2>typescript.timing + Script started, file is typescript + user@caladan:~$ ls + ... + user@caladan:~$ exit + Script done, file is typescript + + Replay a typescript + user@arrakis:~$ scriptreplay typescript + user@caladan:~$ ls + ... + user@caladan:~$ exit + + scriptreplay: typescript time (normal): 14 seconds ( 0 minutes) + scriptreplay: typescript time (accel) : 1 seconds ( 0 minutes) + +NOTES + The playback might not work properly if the typescript contains output + from applications that have been recorded with different termio settings + and/or terminal window sizes. + +COPYRIGHT + This program is in the public domain. + +AUTHORS + Joey Hess + + Marc Schoechlin + + Hendrik Brueckner + +SEE ALSO + script(1), bzcat(1), zcat(1), lzcat(1) +``` diff --git a/recordshell b/recordshell new file mode 100755 index 0000000..870cab4 --- /dev/null +++ b/recordshell @@ -0,0 +1,32 @@ +#!/bin/bash + +LOGDIR="/var/log/recordshell/" +LOGGING_PID="$$" +FILEPREFIX="$LOGDIR/$(date '+%Y-%m-%d')/$(date '+%Y-%m-%d_%H-%M-%S')-$LOGGING_PID"; + +mkdir -p $FILEPREFIX +if [ "$?" != "0" ];then + echo "Unable to create directory structure $FILEPREFIX" + exit 1 +fi + +logger -s -t recordshell "[$LOGGING_PID] Starting logged shell session: ${FILEPREFIX}/typescript, ${FILEPREFIX}/timing (sudo user $SUDO_USER, sudo command $SUDO_COMMAND)" +script -q -f --timing=${FILEPREFIX}/timing ${FILEPREFIX}/typescript +logger -s -t recordshell "[$LOGGING_PID] Finished logged shell session: ${FILEPREFIX}/typescript, ${FILEPREFIX}/timing (sudo user $SUDO_USER, sudo command $SUDO_COMMAND)" + +gzip ${FILEPREFIX}/typescript +if [ "$?" != "0" ];then + logger -s -t recordshell "[$LOGGING_PID] compression of ${FILEPREFIX}/typescript failed" +else + logger -s -t recordshell "[$LOGGING_PID] compression of ${FILEPREFIX}/typescript successful (MD5SUM $(md5sum ${FILEPREFIX}/typescript.gz|awk '{print $1}'))" +fi + +gzip ${FILEPREFIX}/timing +if [ "$?" != "0" ];then + logger -s -t recordshell "[$LOGGING_PID] compression of ${FILEPREFIX}/timing failed" +else + logger -s -t recordshell "[$LOGGING_PID] compression of ${FILEPREFIX}/timing successful (MD5SUM $(md5sum ${FILEPREFIX}/timing.gz|awk '{print $1}'))" +fi + +logger -s -t recordshell "[$LOGGING_PID] execute to review : scriptreplay -t ${FILEPREFIX}/timing.gz ${FILEPREFIX}/typescript.gz" + diff --git a/scriptreplay b/scriptreplay new file mode 100755 index 0000000..314a116 --- /dev/null +++ b/scriptreplay @@ -0,0 +1,324 @@ +#!/usr/bin/env perl + +# +# scriptreplay - play back typescript of terminal session +# +# +# Author(s): +# Joey Hess +# Marc Schoechlin +# Hendrik Brueckner +# +# +use strict; +use warnings; +use File::Basename; +use Getopt::Long; +use IO::Select; +use POSIX; +use Term::ReadKey; + + +sub main(); +sub show_usage(); +sub __exit($;@); +sub open_expr($); + + +my $progname = fileparse($0, qr/\.[^.]+/); +$SIG{__WARN__} = sub { print STDERR "$progname: $_[0]"; }; +$SIG{__DIE__} = sub { print STDERR "$progname: $_[0]"; __exit 254; }; + + +sub main() { + my $time_file; + my $script_file; + my $accel = 1; + + # parse command line options + unless (GetOptions("t|timing=s" => \$time_file, + "a|accelerate=f" => \$accel, + "<>" => sub { $script_file = shift; }, + "h|help" => sub { show_usage(); exit 0; })) { + show_usage(); + exit 1; + } + + # check parameters + die "You need to specify a script file (see also option '-h')\n" unless defined $script_file; + die "Acceleration factor must be greater than 0\n" unless $accel > 0; + + # open script_file + open (SCRIPT, open_expr($script_file)) + or die "Cannot open typescript file $script_file: $!\n"; + unless (