# Constantly Running a Script

**URL:** <https://www.ruby-forum.com/t/constantly-running-a-script/136422>\
**Category:** Rails\
**Created:** [May 1, 2008, 11:00pm UTC](https://www.ruby-forum.com/t/constantly-running-a-script/136422 "2008-05-01T23:00:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [May 1, 2008, 11:00pm UTC](https://www.ruby-forum.com/t/constantly-running-a-script/136422/1 "2008-05-01T23:00:26Z")

</div>

Hello,  
I have a synchronization program built on InstantRails v1.6. I need to  
have an option that makes my program run daily at a certain time. Thus,  
I need a script or something that is constantly running and checking the  
time, then when the time is right, do the sync. Is there a way to do  
this with InstantRails?

Any help is appreciated!

Thanks,

- Jeff M.

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [May 2, 2008, 2:43am UTC](https://www.ruby-forum.com/t/constantly-running-a-script/136422/2 "2008-05-02T02:43:21Z")

</div>

That’s more of an OS function than a rails function isn’t it? So–on  
windows that’d be a scheduled task. Or do I misunderstand the goal?

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [May 2, 2008, 12:32am UTC](https://www.ruby-forum.com/t/constantly-running-a-script/136422/3 "2008-05-02T00:32:54Z")

</div>

Might want to read through some of these articles to set up a cron:

[http://www.google.com/search?client=safari&rls=en-us&q=cron+introduction&ie=UTF-8&oe=UTF-8](http://www.google.com/search?client=safari&rls=en-us&q=cron+introduction&ie=UTF-8&oe=UTF-8)

Then you could put the cron script in the ‘script’ folder of your  
rails application and have it call whatever ruby file you need to run  
at a particular time. So for example, at 5 pm every night I want to  
write ‘Closing Time!’ to the error log:

Add this line to crontab to run at 5:  
00 5 \* \* \* root sh /path/to/your/rails/app/root/folder/foo.sh

In the sh file:  
ruby script/foo.rb run

And then in foo.rb you have whatever code you need, in our case:  
RAILS\_DEFAULT\_LOGGER.error(”\n Closing Time! \n”)

Hope this helps!

ESPNDev

On May 1, 2:00 pm, Jeff M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [May 2, 2008, 3:32am UTC](https://www.ruby-forum.com/t/constantly-running-a-script/136422/4 "2008-05-02T03:32:34Z")

</div>

I think Cron will work. I just have to flesh out everything around it  
before I test it. Thanks!!

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [May 2, 2008, 4:46pm UTC](https://www.ruby-forum.com/t/constantly-running-a-script/136422/5 "2008-05-02T16:46:04Z")

</div>

I"ve been using rufus-scheduler with great results. It serves the same  
function as cron (run a job periodically), but is portable to windows  
and is ruby-centric, and efficient on resources since it’s not  
reloading the rails environment each time a job runs.

```
 http://rufus.rubyforge.org/
```

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [May 3, 2008, 2:07am UTC](https://www.ruby-forum.com/t/constantly-running-a-script/136422/6 "2008-05-03T02:07:26Z")

</div>

I’ve been trying to use the Rufus-Scheduler, but no luck so far with it.  
I have this in one of my controllers:

scheduler.schedule “\* #{params[:month\_time]} #{params[:month\_date]} \* \*”  
do  
`ruby script/push2exchange.rb run`  
end

then the error I get is:

Errno::ENOENT in AutosyncController#index  
No such file or directory - crontab -l

I am running InstantRails 1.6 on Windows Server 2003. Is this error the  
result of it being on Windows? If so, how can I fix it?

Any help is appreciated!

Thanks,

- Jeff M.
