Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add script to generate replay_log from access_log.

  • Loading branch information...
commit 09888c60e7d842f3f8d9756c91d3e4797306b719 1 parent 36f5ae5
Klaas Jan Wierenga kjwierenga authored
Showing with 33 additions and 0 deletions.
  1. +33 −0 make_replay_log.rb
33 make_replay_log.rb
View
@@ -0,0 +1,33 @@
+#!/usr/bin/env ruby
+# Make replay log by extracting the URI from an Apache CLF log file
+# replacing string 'match' by 'substitute' and concatenating them
+# together by replacing \n by \0
+
+progname = File.basename($0)
+
+if ARGV.size < 2
+ puts "Usage: ruby #{progname} 'match' 'substitute' file1 [file2 [file3]] > output_file"
+ puts "Usage: cat logfile | ruby #{progname} 'match' 'substitute' > output_file"
+ puts
+ puts "Example: cat /var/log/access_log | ruby #{progname} '/app' '/' > replay_log"
+ exit
+end
+
+match = ARGV.shift
+sub = ARGV.shift
+
+ARGF.each do |line|
+ request = line.split('"')[1]
+ next if request.nil?
+
+ uri = request.split[1]
+ next if uri.nil?
+
+ begin
+ uri[match] = sub
+ rescue IndexError
+ # simply output line that don't contain the 'replace' string
+ ensure
+ print uri.chomp + "\0"
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.