3

I would like to log actions made in a terminal window, and convert the log to html on fly.

I already tried commands script/screen + ansi2html, but the result is not perfect: the escape sequences for line editing is not handled correctly, so in the resulting html I have a mixture for the old and the new version of the line. So if the output of the terminal is like

$> echo Original text
Original text
$> echo Other
Other

The resulting html is

 $> echo Original text
 Original text
 $> echo Othernal text
 Other

Any idea, how to solve the issue?

6
  • 1
    Refer this link and remove junk char from script output unix.stackexchange.com/questions/86901/… Commented Sep 21, 2013 at 22:16
  • @Rahul: the link you send is interesting, but still the result is not perfect, if I reedit a line. Commented Sep 22, 2013 at 9:00
  • 1
    Can you Update in Question what you have tried so far and what is not working... ? Commented Sep 22, 2013 at 9:12
  • @Rahul I tried the perl script ( perl -pe 's/\e([^\[\]]|\[.*?[a-zA-Z]|\].*?\a)//g'), on a script log, where I have rewritten the line "echo Original text" to "echo Other". In the output, I saw "echo Othernal text" Commented Sep 22, 2013 at 20:11
  • Can you post sample file ? you can use paste.ubuntu.com for the same Commented Sep 23, 2013 at 10:41

1 Answer 1

0

The problem is not your Perl script (which should be unnecessary) but ansi2html which is incomplete.

The logfile shows that something printed some text and then

  • repeatedly added the escape sequence for clearing the remainder of the line \E[K
  • alternately adding a backspace.

In ansi2html, the script finds escape sequences, and then ignores all but a few of those which it finds, i.e.,

self.ansi_codes_prog = re.compile('\033\\\[' '(\[\\d;\]*)' '(\[a-zA-z\])')

if command not in 'mMA':

Getting rid of the repeated stuff is simplest in a loop. Here is an alternate script which works around the problems seen in ansi2html for your example:

#!/usr/bin/perl -w

while (<>) {
    my $save = "";
    while ( $save ne $_ ) {
        $save = $_;
        s/[^\010]\010\e\[K//;
    }
    $save = "";
    while ( $save ne $_ ) {
        $save = $_;
        s/[^\010]\010//;
    }
    s/\e\[\?[;0-9]*[\100-\176]//g;
    s/\e\][^\a]*\a//g;
    print;
}

and (calling that filterit), use it like this:

./filterit < 1.log | ansi2html >1.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .