Setting path for whenever in cron so it can find ruby

John Bachir picture John Bachir · Apr 29, 2011 · Viewed 10.1k times · Source

My ruby is in /usr/local/bin. whenever can't find it, and setting PATH at the top of my cron file doesn't work either, I think because whenever is running the command inside of a new bash instance.

# this does not work
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin

# Begin Whenever generated tasks for: foo
0 * * * * /bin/bash -l -c 'cd /srv/foo/releases/20110429110637 && script/rails runner -e production '\''ActiveRecord::SessionStore::Session.destroy_recent(15)'\'''

# End Whenever generated tasks for: foo

How can I tell whenever where my ruby binary is? Making a symbolic link from /usr/bin seems messy to me, but I guess that might be the only option.

This question offers env :PATH, "..." in schedule.rb as a solution, but (a) I can't find any documentation of that feature anywhere in the docs (b) it doesn't seem to have solved the asker's problem (unfortunately it takes non-trivial turnaround time for me to just try it). update actually it is in the bottom of this page, i'll try it now.

more info

  1. I can't modify the cron command because it's generated by whenever
  2. i verified that if I make a new bash shell with bash -l, /usr/bin/env finds ruby just fine
  3. I just tried the exact command in cron, starting with /bin/bash, from the command line of that user, and it worked.

so, this is very mysterious...

Answer

John Bachir picture John Bachir · May 4, 2011

The solution is to put this in schedule.rb:

env :PATH, ENV['PATH']

Here's a little guide I put together on the topic.