【发布时间】:2015-07-10 03:56:56
【问题描述】:
- 我在 DigitalOcean VPS 上遇到了关于
set crontabUbuntu 14.04 的问题。 - 这是我的步骤:
- 首先,创建新的crontab:
crontab -e - 其次,我设置了这个命令:
- 首先,创建新的crontab:
这是我的 crontab,我将它设置为每天上午 10:26 运行:
26 10 * * * /bin/bash -l -c 'cd /var/www/my_app/current && RAILS_ENV=production bundle exec rake check:user >> log/cron_log.log'
- 第三,我检查了 crontab 为
crontab -l - 最后,我以
sudo service cron restart重新启动crontab
但它无论如何都没有运行(我等到 10:24 到 10:30),我复制了这个命令并在我的控制台中运行它,它运行得很好。
所以,我不明白为什么它的运行方式与 crontab 不同。希望大家能解释一下或者给我一些建议。非常感谢。
编辑:我尝试使用gem whenever,但它没有运行。
set :environment, "production"
env :PATH, ENV['PATH']
env :GEM_PATH, ENV['GEM_PATH']
set :output, {:error => "log/cron_error_log.log", :standard => "log/cron_log.log"}
# Learn more: http://github.com/javan/whenever
every :day, at: '10:26am' do
rake "check:user"
end
我更新了我的 crontab 使用,只要whenever -w
但它不起作用。
更新:
@Coderhs:我尝试运行此命令bundle exec whenever --update-crontab RAILS_ENV=production,但它不起作用:(。
这是我使用命令 crontab -l 时的 crontab 列表:
# Begin Whenever generated tasks for: RAILS_ENV=production
PATH=/var/www/my_app/shared/bundle/ruby/2.2.0/bin:/usr/local/rvm/gems/ruby-2.2.1/bin:/usr/local/rvm/gems/ruby-2.2.1@global/bin:/usr/local/rvm/rubies/ruby-2.2.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/rvm/bin
GEM_PATH=""
26 10 * * * /bin/bash -l -c 'cd /var/www/my_app/releases/20150710024713 && RAILS_ENV=production bundle exec rake user:check --silent >> log/cron_log.log 2>> log/cron_error_log.log'
# End Whenever generated tasks for: RAILS_ENV=production
它仍然没有运行。
更新: 问题解决了。因为在我当地的时间与服务器时间不同。 所以,我刚刚将服务器时间设置为与我的本地时间相同。谢谢大家支持我。
【问题讨论】:
-
当您创建 crontab 时,请确保您是 admin/su。如果那不起作用,请尝试摆脱那些单个滴答声。不要认为你需要它们围绕你的命令
-
@FirebladeDan 是的,我使用了
root许可。但它没有用。
标签: ruby-on-rails crontab ubuntu-14.04