R
R
Roman Volkov2015-08-31 11:50:49
Ruby on Rails
Roman Volkov, 2015-08-31 11:50:49

How to run rake with cron?

You need to run a cron job. I have a script
cd /path_to_project/
bundle exec rake name:action
If I just execute sh update.sh - everything is fine. And if I write the same command in cron, nothing happens

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
O Di, 2015-08-31
@white_wolf_17

Probably because cd doesn't work for you .
stackoverflow.com/questions/255414/why-doesnt-cd-w...
stackoverflow.com/questions/874452/change-current-...

V
vsuhachev, 2015-08-31
@vsuhachev

the problem is that cron has its own environment, for example, in PATH there is no path to either ruby ​​or bundle, shell is different, etc. The correct way is to write your script so that all defaults are explicit - full paths, environment variable initialization, etc.
An easier way is to try to start your shell with the login option and execute the desired command in it. For example, it worked for me on Ubuntu like this
. I don’t presume to judge how “true” it is - perhaps knowledgeable people will comment ...

V
Vayladion Gognazdiak, 2015-09-01
@etspring

In general, for example

SHELL=/bin/sh
PATH=/home/deployer/.rbenv/bin:/home/deployer/.rbenv/bin:/home/deployer/.rbenv/bin:/home/deployer/.rbenv/bin:/home/deployer/.rbenv/bin:/home/deployer/.rbenv/shims:/home/deployer/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
cd /home/deployer/scum_cleaner/current && RAILS_ENV=production bundle exec rake kill:all_gays

In general, it is better to use rufus scheduler

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question