# Schedule Ruby Code!

**URL:** <https://www.ruby-forum.com/t/schedule-ruby-code/119591>\
**Category:** Ruby\
**Created:** [November 8, 2007, 7:54am UTC](https://www.ruby-forum.com/t/schedule-ruby-code/119591 "2007-11-08T07:54:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bashar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b9bd4f/32.png) [@bashar](https://www.ruby-forum.com/u/bashar)\
**Post date:** [November 8, 2007, 7:54am UTC](https://www.ruby-forum.com/t/schedule-ruby-code/119591/1 "2007-11-08T07:54:49Z")

</div>

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.

Your help is really appreciated,  
Regards,

---

<div class="post-metadata">

**Author:** ![bashar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b9bd4f/32.png) [@bashar](https://www.ruby-forum.com/u/bashar)\
**Post date:** [November 8, 2007, 8:29am UTC](https://www.ruby-forum.com/t/schedule-ruby-code/119591/2 "2007-11-08T08:29:54Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Your help is really appreciated,  
> Regards,

If you’re on Linux/ Unix, use cron. If you’re on Windows, use PyCron to  
schedule your code to run at whatever interval you like.

Cheers,  
Mohit.  
11/8/2007 | 3:10 PM.

---

<div class="post-metadata">

**Author:** ![bashar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b9bd4f/32.png) [@bashar](https://www.ruby-forum.com/u/bashar)\
**Post date:** [November 8, 2007, 8:56am UTC](https://www.ruby-forum.com/t/schedule-ruby-code/119591/3 "2007-11-08T08:56:13Z")

</div>

On Nov 8, 2007 3:38 PM, removed\_email\_address@domain.invalid  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](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](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](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](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,

---

<div class="post-metadata">

**Author:** ![bashar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b9bd4f/32.png) [@bashar](https://www.ruby-forum.com/u/bashar)\
**Post date:** [November 8, 2007, 11:45am UTC](https://www.ruby-forum.com/t/schedule-ruby-code/119591/4 "2007-11-08T11:45:27Z")

</div>

On Nov 8, 9:52 am, John M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > want to learn it more.  
> > Now for the scheduling, as Mohit said, let the “cron” system of your
> 
> —\>8—
> 
> more info athttp://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 M. -///- [http://jmettraux.openwfe.org](http://jmettraux.openwfe.org)

Thank you very much John for your help and giving me great tips…!
