I was trying to create a cron job which runs a ruby code on digital ocean, however it seems I'm making a mistake. It doesn't give any error but it doesn't also do anything. I ran this cronjob on my raspberry pi however on digital ocean it doesn't work. Here my cronjob

59 17 * * * ruby /home/workspace/delta/analytics/analyze.rb 7 >> /home/testruby

It creates testruby file but analyze.rb 7 doesn't work. I tested running ruby /home/ .... and it is working. What might be the problem?


error file: bin/sh: 1: /usr/local/bin/ruby: not found

This is what I wrote in my crontab

* * * * * /usr/local/bin/ruby /home/workspace/deriva/analytics/analyze.rb 7 >> /home/testruby 2>&1
  • 1
    There error is a little odd, was there a / in front (/bin/sh:…)? Anyway, are you sure that is the right path to Ruby? ls -l /usr/local/bin/ruby shows it? What about command -v ruby? – derobert May 29 '15 at 17:27
  • @derobert Well, the command that you wrote shows the actual directory of ruby. After giving it, it started to work. Mine is /usr/local/rvm/rubies/ruby-2.1.3/bin/ruby . Thank you – Ahmet Tanakol Jun 1 '15 at 6:23

Different environment variables, working directory, ... You need to debug where exactly analyze.rb is bailing out.

First, you're only redirecting stdout, not stderr. Errors probably go to the later, so adding a 2>&1 to the end may help a lot. Or setting EMAIL= at the top of your crontab to have them mailed to you.

You can confirm that ruby is starting up the print "starting!\n" or similar to the beginning of your Ruby script, and seeing if that shows up in the log file.

| improve this answer | |
  • Thank you, I added what you said, it gives the error "ruby not found". How can this happen? I run the same code on the command line and it is working – Ahmet Tanakol May 28 '15 at 18:33
  • @AhmetTanakol Different $PATH. You can fix by using the full path to ruby or putting a PATH= line at the top of the crontab. – derobert May 28 '15 at 18:38
  • Thank you, I tried to give full path to ruby but still same error. I will search it – Ahmet Tanakol May 28 '15 at 19:02
  • @AhmetTanakol please edit your question to include the new crontab (with the full path to ruby) and the exact error message produced. – derobert May 28 '15 at 19:05
  • I updated my question with the error message. – Ahmet Tanakol May 29 '15 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.