Search code examples
ruby-on-rails-3cronwheneverwhenever-capistrano

How to set PATH variable in crontab via whenever gem


Is it possible to set the PATH or SHELL variable in a crontab via the whenever schedule.rb file?

# here I want to set the PATH and SHELL variable somehow

every 3.hours do
  # some cronjob
end

I want this output in my crontab after my capistrano deploy:

SHELL=/bin/bash
PATH=/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11
# some cronjobs

Solution

  • Ok, it seems as I found the solution. I found it here: https://gist.github.com/jjb/950975

    I will update this answer when I have tested it

    I have to put this into my schedule.rb

    # If your ruby binary isn't in a standard place (for example if it's in /usr/local/bin,
    # because you installed it yourself from source, or from a thid-party package like REE),
    # this tells whenever (or really, the rails runner) where to find it.
    env :PATH, '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin'