bdunagan

Brian Dunagan

June 20 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
Developers: Just Handle It blog.data.visualize()
LinkedIn GitHub Email