mgluesenkamp
mgluesenkamp

Reputation: 529

Run rails runner methods from crontab

We have to run some rails methods from a very old rails app. Because it's so old, we don't want to change the code or install new scheduling tasks or gems. So we try to launch the methods by a simple rails runner command in crontab.

We tried some combinations, but the server is new for us and we don't know, why crontab can't execute the rails runner commands.

These are our attempts:

rails runner ApplicationController.method >> logfile.log
/bin/bash -l -c 'cd /path/to/code && rails runner ApplicationController.method' >> logfile.log
source ~/.bashrc && /bin/bash -l -c 'cd /path/to/code && rails runner ApplicationController.method' >> logfile.log

running a shell script with the rails runner command

ect.

All of the attemps worked in the normal shell (connected by SSH) but it never worked from the crontab. The commands created always the logfile, but it is empty and we make sure that the command isn't executed (checked by rails c).

What can we do to make the crontabs work?

Edit: The server uses rvm to manage the ruby version. Maybe this is the problem.

Upvotes: 2

Views: 823

Answers (1)

Dinesh
Dinesh

Reputation: 548

To execute ruby/rails scripts in crontab use /bin/bash. example:

  * * * * *  /bin/bash -l -c    "ruby /home/abc/sample.rb"

Upvotes: 1

Related Questions