简体   繁体   中英

Execute rake command inside bash

I am seeing many times the question about execution of bash files inside rake (task) files.

My question is, how to execute a rake command inside the bash file? I have a migrate.sh file inside each rails app on my server and I'm using a general publish.sh . All of this runs ok.

Then, I have a command like rake tmp:clear assets:clean log:clear RAILS_ENV=production inside each migrate.sh that gives me a rake: command not found error.

Help?

Basically rake is not resolved as the PATH variable is not correct. You can try doing echo $PATH . Also you can create a bash script and provide some environment variables required by rake like this:

#!/bin/bash

GEM_HOME=/home/tuxdna/.gems
SHELL=/bin/bash
USER=tuxdna
PATH=/home/tuxdna/.gems/bin:/usr/lib/ruby/gems/1.8/bin/:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
GEM_PATH=/home/tuxdna/.gems:/usr/lib/ruby/gems/1.8

cd ~/somesite
export RAILS_ENV=production
bundle exec rake mytask:task1

klashxx's supposition was correct. It was a permissions/profile issue. I had change my user to root to be able to do other previous tasks and found out that my root was not able to run rake tasks.

This will not be an issue on production server though.

Thanks klashxx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM