Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know I can replay terminal actions with:

scriptreplay /path/to/$STARTTIME-timing.txt /path/to/$STARTTIME-log.txt

But how can I replay the actions from, for example, the 2nd to the 3rd minute? Does scriptreplay only offer a "speed up/slow down" option?

share|improve this question
"How to use ..." seems a bit too broad and vague as a title for the question - could you change it perhaps to something like "Extended playback options for scriptreplay (e.g. playback speed, seek, start, end etc.)?"? – jw013 Jan 7 '12 at 17:46
up vote 4 down vote accepted

There's a perl version of scriptreplay that's in the public domain, provided by Joey Hess: scriptreplay.

You can adapt that to add start/end features (the author placed that implementation in the public domain).

Here's a quick and dirty modification of that code that takes two additional parameters - the start time (in seconds from start, default 0), and the end time (optional, runs till the end if not specified). Adapt to suit your needs:

#!/usr/bin/perl -w
use strict;
open (TIMING, shift)
        or die "cannot read timing info: $!";
open (TYPESCRIPT, shift || 'typescript')
        or die "cannot read typescript: $!";
my $divisor=shift || 1;
my $start_sec=shift || 0;
my $end_sec=shift;
# Read starting timestamp line and ignore.
my $printing = ($start_sec > 0 ? 0 : 1);
my $elapsed = 0;
my $block;
my $oldblock='';
while (<TIMING>) {
        my ($delay, $blocksize)=split ' ', $_, 2;
        if ($printing && ($delay / $divisor > 0.0001)) {
                select(undef, undef, undef, $delay / $divisor - 0.0001);
        read(TYPESCRIPT, $block, $blocksize) or die "read failure: $!";
        print $oldblock if ($printing);

        $elapsed += $delay;
        exit if ((defined $end_sec) && ($elapsed > $end_sec));
        $printing = ($elapsed > $start_sec);

print $oldblock;
share|improve this answer
I don't really 100% understand perl..ehh. how can I use this? ex.: I put this perl script to "repl.pl" and then: "perl repl.pl TIMINGFILE TYPESCRIPTFILE STARTTIME ENDTIME"? - sorry for asking this :D – LanceBaynes Jan 4 '12 at 12:40
You forgot the divisor as the third argument (before start time, set to 1 for normal speed), but that's pretty much it. – Mat Jan 4 '12 at 12:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.