bdunagan

fill the void - bdunagan

20 Jun 2011
Server Tip: preserve the user environment

crontab and sudo don't preserve the user environment by default. Here are ways to fix that:

# crontab allows variables.
PATH=/home/user/.gems/bin:/usr/local/bin:/usr/bin:/bin
GEM_PATH=/home/user/.gems:/usr/lib/ruby/gems/1.8
@hourly sh -c '/usr/bin/ruby /home/user/script.rb'

# sudo can preserve the environment with '-E'.
sudo -E ruby /home/user/script.rb
Previous LinkedIn Twitter GitHub Email Next