【问题标题】:R cronjob wrong date and timeR cronjob错误的日期和时间
【发布时间】:2016-06-20 08:34:28
【问题描述】:

我有一个 R 脚本,可以生成给定时间段(1 周)的统计数据。当我从命令行运行脚本时,一切都按预期工作。但是当我尝试使用 cron 作业生成统计信息时,日期和时间函数不正确。

我的 crontab:

/usr/bin/Rscript -e "rmarkdown::render('stats.Rmd', output_file = file.path('/tmp/stats.html'))"

Rmd 文件:

---
title: "Stats"
output: html_document
---

Stats begin: `r as.Date(as.numeric(Sys.Date())-7, origin="1970-01-01")`
Stats end:   `r Sys.Date()`
[...]

统计数据的开始和结束时间始终是上次执行的时间。

我已经尝试删除生成的html文件并使用--vanilla调用Rscript,但没有成功。

【问题讨论】:

    标签: r date datetime cron


    【解决方案1】:

    我找到了自己的解决方案:

    我写了一个小 R 脚本,而不是现有的 crontab:

    #!/usr/bin/env Rscript
    rmarkdown::render('/.../stats.Rmd', output_file = file.path('/tmp/stats.html'))
    

    并更新了我的 crontab

    .../stats.R
    

    这解决了我的奇怪行为。

    【讨论】:

      猜你喜欢
      • 2021-12-04
      • 2020-03-24
      • 1970-01-01
      • 1970-01-01
      • 2020-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-15
      相关资源
      最近更新 更多