bora
By:
bora

Can't get Cron to work

January 2, 2014 2.5k views
Hi guys, I'm having an issue with Cron to work.This is what I have in the crontab, that's supposed to run every 5 minutes on Thursday: SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin */5 * * * 4 root cd /home/rails/jukely-web && rails runner -e production 'Pinger.send_test_sms' But it's not running. If I execute cd /home/rails/jukely-web && rails runner -e production 'Pinger.send_test_sms' from the console it runs fine. Am I missing something in the syntax or config I wonder. I read the docs and checked the other questions but no dice. Thanks, Bora
10 Answers
Run
which rails
-- what does that output?
Hi Kamal, didn't get a notification about your comment so didn't see it until now. It outputs:

/usr/local/rvm/gems/ruby-1.9.3-p448/bin/rails
Ok, replace PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin with PATH=/usr/local/rvm/gems/ruby-1.9.3-p448/bin/rails:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
No dice. Here is everything I have in the crontab.

SHELL=/bin/sh
PATH=/usr/local/rvm/gems/ruby-1.9.3-p448/bin/rails:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
* * * * * root cd /home/rails/jukely-web && rails runner -e production 'Pinger.send_test_sms'

and I just tried running

cd /home/rails/jukely-web && rails runner -e production 'Pinger.send_test_sms'

whic works fine, sends me the test SMS.
How are you editing the cron file/config?
In that case, you don't need the "root". This should work:
SHELL=/bin/sh 

PATH=/usr/local/rvm/gems/ruby-1.9.3-p448/bin/rails:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
* * * * * cd /home/rails/jukely-web && rails runner -e production 'Pinger.send_test_sms'
Yeah I tried removing root before and now again and it didn't help. I'm happy to give you access to the droplet if you'd like to take a look. Thanks Kamal!

Bora
Try creating a file with this as its contents:
#!/bin/bash

PATH=/usr/local/rvm/gems/ruby-1.9.3-p448/bin/rails:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
cd /home/rails/jukely-web
rails runner -e production 'Pinger.send_test_sms'

and editing your crontab file to look like this:
* * * * * bash /path/to/file
Just did that and still not working. I'd be happy to give you access to the droplet and put an end to this month long ticket :)
Have another answer? Share your knowledge.