1

I normally run stinkypete.rb script using bash terminal and then run

  ruby stinkypete.rb

I'm trying to create cronjob for same using nano editor in ubuntu 16.04 and here is line for crontab that i've written.

*/1 * * * * export /home/orion/.bashrc -c '/home/orion/stinkypete/stinkypete.rb'

Checking service cron status, its running but script doesn't work. Is there any other path that I need to load in crontab?

Kaijju
  • 143
  • 10
  • What do you mean doesn't work? – Fangxing Aug 10 '17 at 15:43
  • You may wanna check this gem [cron jobs in Ruby](https://github.com/javan/whenever) – Fangxing Aug 10 '17 at 15:46
  • by doesn't work i mean script doesn't run , I checked whenever gem but it requires config file which my script doesn't have – Kaijju Aug 10 '17 at 16:16
  • If you are using rvm or some other ruby manager,this is because cron know nothing about where is your ruby and gems, you may want to load some ruby environment, like load ruby to the $PATH`, check [this](https://unix.stackexchange.com/questions/27289/how-can-i-run-a-cron-command-with-existing-environmental-variables) – Fangxing Aug 11 '17 at 00:48
  • I'm using rbenv – Kaijju Aug 12 '17 at 16:21
  • See this question https://stackoverflow.com/questions/8434922/ruby-script-using-rbenv-in-cron – Fangxing Aug 13 '17 at 13:13

1 Answers1

1

Since you are using rbenv, cron job will not kown where is you ruby before your tell him, so you need init rbenv first, so try this

*/1 * * * * /bin/bash -c 'export PATH="$HOME/.rbenv/bin:$PATH" ; eval "$(rbenv init -)"; ruby /home/orion/stinkypete/stinkypete.rb'
Fangxing
  • 5,716
  • 2
  • 49
  • 53