Ruby script under cron

I have a number of custom scripts that run at the console. Now I want
cron
to take over and run them on a daily basis. If I /usr/bin/run-parts
/etc/cron.daily
at the console all jobs run fine. However, if I leave it to cron and
check next day
there was no indication the scripts had run at all. No change in output
to log.

I wonder if ruby is not able to run under the cron shell (is it that
different than sh?).

Has anyone had to deal with this or can offer a suggestion?

Thanks,

Long

I have several rails scripts that run

ruby /dir/to/app/script/runner 'Actions'

and they run just fine. This is on Arch Linux. If you can run them
through the cron command manually, I don’t see why it wouldn’t work from
crond. Could it be some sort of permissions issue?

Jason

Jason N. wrote:

I have several rails scripts that run

ruby /dir/to/app/script/runner 'Actions'

and they run just fine. This is on Arch Linux. If you can run them
through the cron command manually, I don’t see why it wouldn’t work from
crond. Could it be some sort of permissions issue?

Jason,

Well crond runs as root so I don’t think permission is the problem. The
difference
seems to be in how I run the script.

ruby /path/script/my_script

Now that you mention it I vaguely recall reference to runner usage. Let
see
if I have this right.

I should
ruby script/generate task my_script
then
ruby /path/script/runner ‘MyScript’
to run it.

Any thoughts?

Thanks,

Long

Hi, Long,

Search the archive of this list for “cron mazel tov” and read to the
end of that thread. It might help.

I should
ruby script/generate task my_script

hmm… there is no ‘task’ script. See ruby script/generate --help. Also
found this link

http://wiki.rubyonrails.org/rails/pages/HowToRunBackgroundJobsInRails/

Long

Zachary H. wrote:

Hi, Long,

Search the archive of this list for “cron mazel tov” and read to the
end of that thread. It might help.

I searched on gmane and only found the last posting. But did find many
postings when search with “cron”.

I believe my scripts were missing the ruby initialization line.

#!/usr/bin/env ruby
require File.dirname(FILE) + ‘/…/config/boot’
Line taken from script/generate and the likes.

I already had the require environment line needed to access my models.

require File.dirname(FILE) + ‘/…/config/environment’

I think I will create a utility class and put all my scripts there. It
will
help clean up my code for sure. Then I can use script/runner
to start the process. In this way all scripts will run under one rails
env instead of a separate one for each.

Thanks again everyone,

Long

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs