From: John Mettraux Date: 2007-11-08T16:52:09+09:00 Subject: Re: Schedule Ruby Code! On Nov 8, 2007 3:38 PM, bashar.ayyash@gmail.com wrote: > Hello, > > I want to build a ruby script that list contents of a folder and put > this list in a generated XML files (actually two files), and I want to > schedule this script to run every 30 minutes. > > Pls. if you could tell me where I should start and how to make this > script run every 30 minutes, I'm new to the language I liked it and I > want to learn it more. Hi Bashar, To list the content of a folder, take a look at the Dir class (http://corelib.rubyonrails.org/classes/Dir.html), if you need something a bit more 'recursive', look at Find (http://stdlib.rubyonrails.org/libdoc/find/rdoc/index.html). To generate the XML file, have a look at REXML, http://www.germane-software.com/software/rexml/docs/tutorial.html Now for the scheduling, as Mohit said, let the "cron" system of your platform run your job. If you want to stay Ruby, you can use the OpenWFEru scheduler and write something like : ---8<--- require 'rubygems' require 'openwfe/util/scheduler' # sudo gem install openwferu-scheduler s = OpenWFE::Scheduler.new s.start s.schedule("0,30 * * * *") do # twice per hour, at minute 0 and at minute 30 generate_xml_file() # your method end --->8--- more info at http://openwferu.rubyforge.org/scheduler.html If your script is just a sysadmin helper, it's probably wiser to stick with the cron utility of your platform. Best regards, -- John Mettraux -///- http://jmettraux.openwfe.org