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
Keyword(s):[blog] [ruby] [tail] [web] [firefox] [rikaichan] [japanese] [snippet] [subpar] [frontpage]
References:[Ruby]