Crontab not running ruby script

Viewed 10406

The crontab -l below doesn't seem to run. The script run by hand runs fine. Here is the error i'm seeing

Dec  3 20:12:01 dahlia /USR/SBIN/CRON[13912]: (gigawatt) CMD (/bin/sh -c "(export   PATH=/usr/bin:/bin; /home/gigawatt/drbronnersbot/drbronnersbot.rb)")
Dec  3 20:12:01 dahlia /USR/SBIN/CRON[13910]: (CRON) error (grandchild #13912 failed with exit status 1)

And here is the crontab:

* * * * * /bin/sh -c "(export PATH=/usr/bin:/bin; /home/gigawatt/drbronnersbot/drbronnersbot.rb)"

Permissions are fully open, its executable, i put the env path at the beginning of the file, still no dice.

5 Answers

This is quite old but thought I'd comment anyway. RVM creates a wrapper for each version of ruby you install.

run this command replace 2.5.1 with your ruby version

rvm env --path 2.5.1

this gives you the path to the environment mine is

/home/username/.rvm/environments/2.5.1

you want just the rvm path

/home/username/.rvm/

take a look at the wrappers directory there should be a wrapper for each version and gemset you have installed. Test your script with the wrapper

/home/username/.rvm/wrappers/ruby-2.5.1/ruby /home/username/scripts/script.rb

or if you have a specific gemset

/home/username/.rvm/wrappers/ruby-2.5.1@gemset/ruby /home/username/scripts/script.rb

Use this command directly in your crontab

* * * * * /home/username/.rvm/wrappers/ruby-2.5.1/ruby /home/username/scripts/script.rb

Solved it, i was calling two files in my code and it couldn't find those files. I editing the .rb file to include the full path and it works perfectly now. Thanks everyone!

Have you tried:

* * * * * /home/gigawatt/.rvm/rubies/ruby-2.0.0-p247/bin/ruby /home/gigawatt/drbronnersbot/drbronnersbot.rb
Related