Skip to main content
2 of 2
added 1443 characters in body
Michael Mrozek
  • 95.8k
  • 40
  • 245
  • 236

I solved the problem by running scriptreplay in a screen and the dumping the scrollback buffer to a file.

The following expect script does this for you.

It has been tested for logfiles with up to 250.000 lines. In the working directory you need your scriptlog, a file called "time" with 10.000.000 times the line "1 10" in it, and the script. I needs the name of your scriptfile as command line argument, like ./name_of_script name_of_scriptlog.

#!/usr/bin/expect -f set logfile [lindex $argv 0] if {$logfile == ""} {puts "Usage: ./script_to_readable.exp \$logfile."; exit} set timestamp [clock format [clock sec] -format %Y-%m-%d,%H:%M:%S] set pwd [exec pwd] if {! [file exists ${pwd}/time]} {puts "ERROR: time file not found.\nYou need a file named time with 10.000.000 times the line \"1 10\" in the working directory for this script to work. Please provide it."; exit} set wc [exec cat ${pwd}/$logfile | wc -l] set height [ expr "$wc" + "100" ] system cp $logfile ${logfile}.tmp system echo $timestamp >> ${logfile}.tmp set timeout -1 spawn screen -h $height -S $timestamp send "scriptreplay -t time -s ${logfile}.tmp 100000 2>/dev/null\r" expect ${timestamp} send "\x01:hardcopy -h readablelog.${timestamp}\r" send "exit\r" system sed '/^$/d' readablelog.$timestamp >> readablelog2.$timestamp system head -n-2 readablelog2.$timestamp >> ${logfile}.readable.$timestamp system rm -f readablelog.$timestamp readablelog2.$timestamp ${logfile}.tmp 

The time file can be generated by

for i in $(seq 1 10000000); do echo "1 10" >> time; done