为什么(ANA)CRON不能运行我的任何工作,并没有输出错误?

我有一个cron作业安装,但没有运行。 我用crontab -e安装了它,并input以下内容。

 0 12 * * * /var/www/drupal/scripts/dump_sites * * * * * wall /tmp/test 

我把第二个命令用于testing目的。 确实有一个文件/ tmp / test,它只是“这是一个testing”。

当我退出crontab -e我收到没有错误消息。 /var/log/中没有cron的日志文件。 我停止与service cron stop并试着用cron -L 2启动它得到更好的debugging输出,但仍然没有日志。

我已经手动运行了/var/www/drupal/scripts/dump_sites ,并得到了预期的行为,即输出文件出现在我想要的地方。 当我用cron尝试时,我没有得到预期的行为。

当我做ps aux | grep cron ps aux | grep cron我可以看到它与一个关联的进程ID。

我暂时放弃了cron,并尝试了anacron。 ps aux | grep cron ps aux | grep cron现在产生以下内容。 然而; 我的dump_sites脚本仍然不能运行。

 devcampus :: /var/www/drupal » ps aux | grep cron root 15635 0.0 0.1 12440 928 ? Ss 11:59 0:00 anacron -f root 15816 0.0 0.1 4092 608 ? S 12:04 0:00 /bin/sh -c nice run-parts --report /etc/cron.daily root 15818 0.0 0.1 3996 620 ? SN 12:04 0:00 run-parts --report /etc/cron.daily root 15825 0.0 0.1 4092 680 ? SN 12:04 0:00 /bin/sh /etc/cron.daily/apt 

我的/etc/anacrontab文件看起来像这样。

 # /etc/anacrontab: configuration file for anacron # See anacron(8) and anacrontab(5) for details. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # These replace cron's entries 1 5 cron.daily nice run-parts --report /etc/cron.daily 7 10 cron.weekly nice run-parts --report /etc/cron.weekly @monthly 15 cron.monthly nice run-parts --report /etc/cron.monthly # period delay job-identifier command @daily 14 backup /var/www/drupal/scripts/dump_sites 

我正在运行Ubuntu 10.04,我相信这个盒子是在Xen虚拟化服务器上​​运行的。

 devcampus :: /var/www/drup 2.6.32-23-server 

更新:显然它与anacron工作。


根据请求,这里是dump_sites

 #!/usr/bin/env ruby DRUPAL_ROOT = File.expand_path(File.dirname(__FILE__) + '/../') SITES_ROOT = File.join(DRUPAL_ROOT, 'sites') CONFIG_FILES = Dir.glob(File.join(SITES_ROOT, "*", "dbconfig.php")) databases = CONFIG_FILES.map do |cf| contents = File.read(cf) contents =~ /dbname='(.*)'/ ? $1 : nil end databases.uniq! databases.sort! databases.each do |db| file_name = File.join(DRUPAL_ROOT, "db_dumps", "#{db}_#{Time.now.strftime("%Y-%m-%d-%H-%M-%S")}.sql") `mysqldump -uusername -ppassword #{db} > #{file_name}` end 

只是一个普通的老ruby剧本。

您的cron运行应logging在/var/log/syslog 。 如果出现错误,您应该收到电子邮件。

通常当一个脚本从命令行运行,而不会从cron这是因为环境的差异。 明确设置PATHvariables和/或使用完整path指向所有文件和可执行文件是一个好主意。 我看到你已经在你的crontab条目中做了这个,但你应该检查脚本本身。

PATH之外,您的脚本还可能还有其他环境依赖项。 没有看到它,我不能猜测他们可能是什么。

请记住,cron脚本不能与完整的用户环境(PATH等)一起运行,所以cron很可能正在运行脚本,但脚本不能正常工作。

cron错误通常会发送到邮件。 你有没有试过检查? 只需在命令行input邮件,你就可以看到来自cron的邮件列表。