#---
# Excerpted from "Rails Recipes"
# We make no guarantees that this code is fit for any purpose. 
# Visit http://www.pragmaticprogrammer.com/titles/fr_rr for more book information.
#---
require 'active_record' 
ActiveRecord::Base.establish_connection(
  :adapter  => "mysql", 
  :host     => "localhost", 
  :username => "nightlybatch", 
  :password => "secret", 
  :database => "web_orders"
)

class Order < ActiveRecord::Base
end
ActiveRecord::Base.logger = Logger.new(STDOUT) 

Order.find(:all).each do |o|
  puts "Processing order number #{o.id}"
  `./sendorder -c #{o.customer_id} \
     -p #{o.product_id} \
     -q #{o.quantity}`
end