UNIX notes

Main Site : CNK's space : Unix Notes
One of the main things that I run this server for is so that I have a place ot collect all the bits and pieces of knowledge that I keep finding and losing again in the course of becoming a programer/sysadmin/DBA.

One major source of annoyance is setting up my environment again every time I change computers. Some of the things I need to drag with me all the time are:

And the indispensible perl script for doing substitutions in a set of files: perl-subs.pl

And for future reference - here is the perl one-liner that gets rid of the extra space in ZServer/Zope logs that makes Analog reject them all:

perl -i.bak -ne 's/^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})  - /$1 - / ; print ' Z2.log

Misc

Cool book on Unix and Mac OsX by an ex-aD collegue: Mac OS X and Unix Programming

Ruby

How to get a stack trace in Ruby:

begin
 [PUT YOUR CODE HERE TO BE TESTED]
rescue => e
  puts "Error during processing: #{$!}"
  puts "Backtrace:\n\t#{e.backtrace.join("\n\t")}"
end

Capturing output for testing (from an example on the Spinach web site.

require 'stringio'
def capture_output
    out = StringIO.new
    $stdout = out
    $stderr = out
    yield
    return out.string
ensure
    $stdout = STDOUT
    $stderr = STDERR
end
Or, in Ruby 1.9, capture_io is available because it is part of MiniTest: capture_io

Other Sections


cnk@ugcs.caltech.edu