Skip to content

Instantly share code, notes, and snippets.

@jrunning
Created June 30, 2014 18:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrunning/ddc026df5d50645ae24e to your computer and use it in GitHub Desktop.
Save jrunning/ddc026df5d50645ae24e to your computer and use it in GitHub Desktop.
Instant Ruby CGI server
#!/usr/bin/env ruby
require "webrick"
server = WEBrick::HTTPServer.new(Port: 8080, DocumentRoot: Dir::pwd)
trap("INT") { server.shutdown }
server.start
#!/usr/bin/env ruby
require "cgi"
NUM_LINES = 20
FILE_TO_TAIL = "/var/log/system.log"
COMMAND = "| tail -#{NUM_LINES} #{FILE_TO_TAIL}"
cgi = CGI.new
open(COMMAND) {|io| cgi.out("text/plain", &io.method(:read)) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment