问题描述
我在使用 cron 和 RVM 执行脚本/运行程序时遇到了困难.我相信问题在于在运行程序执行之前没有设置 rvm 环境.
I'm having a rough time executing script/runner with a cron and RVM. I believe the issues lie with the rvm environment not being set before the runner is executed.
目前我正在抛出错误/bin/sh: 1.sql: 命令未找到这比我之前得到的要多,所以我想这很好.
currently im throwing the error /bin/sh: 1.sql: command not foundwhich is more than i've gotten earlier, so i guess that's good.
我读过这个帖子需要在每个 cron 作业之前设置 rvm 环境,但我仍然没有真正得到它.我认为部分问题是错误报告.
I've read this thread Need to set up rvm environment prior to every cron job but im still not really getting it. Part of the problem i think is the error reporting.
到目前为止,这是我的跑步者.
this is my runner thus far.
*/1 * * * * * /bin/bash -l -c 'rvm use 1.8.7-p352@2310; cd development/app/my_app2310 && script/runner -e development "Mailer.find_customer"'
根据上面的链接,我尝试制作一个 rvm_cron_runner.
as per the above link, i tried making a rvm_cron_runner.
我创建了一个文件并将其放入其中:
i created a file and placed this in it:
#!/bin/sh
source "/Users/dude/.rvm/scripts/rvm"
exec $1
然后我将我的 crontab 更新为这个.
then i updated my crontab to this.
*/1 * * * * * /bin/bash -l -c '/Users/dude/development/app/my_app2310/rvm_cron_runner; rvm use 1.8.7-p352@2310; cd development/app/my_app2310 && script/runner -e development "Mailer.find_customer"'
这也没什么区别.我没有错误.什么都没有.
This also has made no difference. i get no error. nothing.
谁能看到我做错了什么?
Can anyone see what i'm doing incorrectly?
P.S 我希望我的代码格式有效.
P.S i hope my code formatting worked.
推荐答案
能否尝试将要运行的代码放在单独的脚本中,然后使用 rvm_cron_runner
?
Could you try to place the code you want to run in a separate script, and then use the rvm_cron_runner
?
因此将您的操作放在名为 /path/cron_job
So place your actions in a file called /path/cron_job
rvm use 1.8.7-p352@2310
cd development/app/my_app2310 && script/runner -e development "Mailer.find_customer"
然后在你的 crontab 中写
and then in your crontab write
1 2 * * * /path/rvm_cron_runner /path/cron_job
区别:
- 这不会启动一个单独的 shell
- 使用
rvm_cron_runner
的参数
如果您要使用 .rvmrc
文件,我认为您甚至可以删除 rvm use ...
行.
If you would use an .rvmrc
file, you could even drop the rvm use ...
line, I think.
这篇关于RVM 没有使用 cron 设置环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!