Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using backup_fu to backup my database. In the crontab, you have this command:

* * * * * cd /var/www/amplify/current && RAILS_ENV=production /usr/bin/env rake backup

Yes, I know a backup a minute is intense, but I'm just doing it to test. I will change the interval once I get it working.

  • However, running it in cron doesn't it backup. When I check my Amazon S3 account, I don't see a .tar.gz file.
  • When I SSH in, and I paste the command exactly, it backs up and I see the .tar.gz in Amazon S3.


  • I'm using RVM. However, as shown in this thread, if I cd into the directory, the proper ruby selection happens.
  • I'm on CentOS: Linux version 2.6.18-194.8.1.el5.028stab070.5 (root@rhel5-build-x64) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) #1 SMP Fri Sep 17 19:10:36 MSD 2010
  • I checked /var/log/cron and it seems that it runs: Feb 27 00:20:01 amplify crond[1667]: (ramon) CMD (cd /var/www/amplify/current && RAILS_ENV=production /usr/bin/env /usr/bin/rake backup)

Any help is appreciated, thanks!

share|improve this question
up vote 2 down vote accepted

It seems that this ended up becoming an RVM issue, and not a server one. I apologize. Thanks for your answers; they've helped me figure it out.

The final one that worked was:

cd /var/www/amplify/current && source /home/ramon/.rvm/environments/ree-1.8.7-2010.02@rails3 && RAILS_ENV=production /home/ramon/.rvm/gems/ree-1.8.7-2010.02@rails3/bin/rake backup &>/home/ramon/backup.log

The key was to use source /home/ramon/.rvm/environments/ree-1.8.7-2010.02@rails3.

When I asked Wayne Seguin about cd'ing into the directory and autoloading .rvmrc, he said it'll only work if:

  • RVM is loaded properly as a function (type rvm | head -1)
  • The .rvmrc has been trusted previously

So it seems that in cron, RVM isn't loaded properly as a function, since I've "trusted" the .rvmrc before.

share|improve this answer

Have you checked the mail for the account running the cron job, output from the command should appear there and may contain clues as to the problem.

Capture the output of the command to a file add &>/path/to/logfile to the end of the command to find out what is happening.

share|improve this answer
Thanks. With this I was able, to pinpoint the problem to RVM, it seems. I'm still investigating further and will update you. – Ramon Tayag Feb 27 '11 at 18:30


/usr/bin/env rake backup

depends on the PATH containing the location of rake. It's the same as simply having

rake backup

The environment for cron is different than that for your interactive session. Change the line in your crontab to point directly to the rake executable:

* * * * * cd /var/www/amplify/current && RAILS_ENV=production /path/to/rake backup

or set your crontab's PATH (within the crontab) to include it:

share|improve this answer

Setting PATH in your crontab isn't very portable I suggest you do something like this:

~ $ rvm env --path                                                                                                                                  

What in that file:

~ $ cat `rvm env --path`                                                                                                                            
export PATH ; PATH="/Users/james/.rvm/gems/ruby-1.9...

So we can do this:

~ $ crontab -e
0 * * * * source /Users/james/.rvm/environments/ruby-1.9.3-p392 && command
# or 
0 * * * * rvm use 1.9.3@myenv && source `rvm env --path` && command
share|improve this answer

Put your cronjob into separate script and call it in crontab.

cd /var/www/amplify/current && RAILS_ENV=production /usr/bin/env rake backup
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.