Piping logs and stuff through HTTP
Ever wanted to pipe a tail -f through HTTP? I made a quick hack in order to use the excellent rikaichan extension for Firefox in real-time IRC conversations:
I was going to code a File::Tail but a quick look at the RAA pointed me to Florian Frank's file-tail, making the remaining code trivial:
#!/usr/bin/env ruby require 'tail' require 'socket' require 'cgi' port = 54321 sock = TCPServer.new('localhost', port) loop do Thread.start(sock.accept) do |conn| conn.sync = true conn.puts <<EOF HTTP/1.0 200 OK Content-Type: text/html <html><body> EOF File::Tail::Logfile.open(ARGV[0], :rewind => 10) do |log| log.tail { |line| conn.puts "#{CGI::escapeHTML(line)}<br />" } end end end
Referer
- 40 http://search.live.com/results.aspx?q=anarchaia&mrt=en-us&FORM=LIVSOP
- 22 http://anarchaia.org
- 19 http://planetruby.0x42.net
- 16 http://www.artima.com/forums/flat.jsp?forum=123&thread=154470
- 8 http://www.anarchaia.org
- 8 http://anarchaia.org/archive/2006/03.html
- 7 http://www.artima.com/buzz/community.jsp?forum=123
- 6 http://search.live.com/images/results.aspx?q=file extension irc&FORM=SSIX
- 6 http://search.live.com/images/results.aspx?q=file extension png&FORM=BIRE
- 6 http://search.live.com/images/results.aspx?q=file extension class&FORM=BIRE
Keyword(s):[blog] [ruby] [tail] [web] [firefox] [rikaichan] [japanese] [snippet] [subpar] [frontpage]
References:[Ruby]