Mega Code Archive

 
Categories / Ruby / CGI
 

Nested cgi tag to create HTML document

#!/usr/bin/ruby require 'cgi' cgi = CGI.new('html3') processes = 'ps aux'.collect { |proc| proc.split(/\s+/, 11) } title = %{Processes running on #{ENV['SERVER_NAME'] || %x{hostname}.strip}} cgi.out do   cgi.html do     cgi.head { cgi.title { title } } + cgi.body do       cgi.table do         (processes.collect do |fields|           cgi.tr { fields.collect { |field| cgi.td { field } }.join " " }         end).join "\n"       end     end   end end exit 0