简体   繁体   English

在bash中执行rake命令

[英]Execute rake command inside bash

I am seeing many times the question about execution of bash files inside rake (task) files. 我多次看到有关在rake(任务)文件中执行bash文件的问题。

My question is, how to execute a rake command inside the bash file? 我的问题是,如何在bash文件中执行rake命令? I have a migrate.sh file inside each rails app on my server and I'm using a general publish.sh . 我在服务器上的每个Rails应用程序中都有一个migrate.sh文件,并且使用的是常规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. 然后,我在每个migrate.sh中有一个类似rake tmp:clear assets:clean log:clear RAILS_ENV=production rake: command not found ,这给了我rake: command not found错误。

Help? 救命?

Basically rake is not resolved as the PATH variable is not correct. 基本上,由于PATH变量不正确,因此无法解决rake You can try doing echo $PATH . 您可以尝试执行echo $PATH Also you can create a bash script and provide some environment variables required by rake like this: 您还可以创建一个bash脚本并提供rake所需的一些环境变量,如下所示:

#!/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. klashxx的假设是正确的。 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. 我已将用户更改为root才能执行其他先前的任务,但发现我的root无法运行rake任务。

This will not be an issue on production server though. 不过,这在生产服务器上将不是问题。

Thanks klashxx 谢谢klashxx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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