运行 bash 使用 R Markdown 作为 Cron 作业的脚本
Running bash script as Cron job with R Markdown
我想尝试如何从 bash 脚本 运行ning 作为 Cron 作业从 R markdown 文件呈现 html。我不知道为什么一切正常,除了 运行ning 作为 Cron 作业。我做什么:
我的脚本是来自 Rstudio 的演示脚本
---
title: "test"
author: "sms"
date: "24 maja 2015"
output: html_document
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
etc.
这个脚本在 Rstudio 中没有任何问题。
接下来我尝试 运行 来自终端的 Rmd 脚本:
Rscript -e "require( 'rmarkdown' ); render('/home/sms/Dokumenty/R/test.Rmd', 'html_document')"
没有任何问题。有效。
所以我创建了bash脚本
#!/bin/bash
Rscript -e "require('rmarkdown'); render('/home/sms/Dokumenty/R/test.Rmd', 'html_document')"
并更改了 chmod 755 test.sh
也很有魅力。
但是当放入 Cron 文件时(管理员和用户):
28 18 * * * sh /home/sms/Dokumenty/R/test.sh
没用
知道我做错了什么吗?
简化,简化,再简化。
首先,我将其设为 Rscript,可能名为 renderTest.R
#!/usr/bin/Rscript
library(rmarkdown)
setwd("/home/sms/Dokuments/R")
render("test.Rmd") # I usually use default arguments
其次,使脚本可执行(chmod 0755 renderTest.R
)。
三、测试脚本。如果你可以 运行 像你一样,一个 cron 作业 运行ning 你也应该这样做。
第四,添加cronjob 运行ning作为you拥有同样的权利
编辑 我刚刚修正了一个从您那里复制的错字:Documents/
而不是 Documenty/
.
我也有同样的问题。
但如果您尝试使用 knitr::knit2html 而不是 rmarkdown::render
,它会起作用
关于为什么
我遇到了同样的问题。
问题是因为我 运行 将 Rscript 设置为 root,但 Rscript 应该 运行 作为 souza,当前用户。
为了解决这个问题,我为用户 souza "sudo crontab -u souza -e" 编辑了 crontab,Rscript 是 运行 作为 souza 而不是 root。
现在正在运行
我想尝试如何从 bash 脚本 运行ning 作为 Cron 作业从 R markdown 文件呈现 html。我不知道为什么一切正常,除了 运行ning 作为 Cron 作业。我做什么:
我的脚本是来自 Rstudio 的演示脚本
---
title: "test"
author: "sms"
date: "24 maja 2015"
output: html_document
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
etc.
这个脚本在 Rstudio 中没有任何问题。
接下来我尝试 运行 来自终端的 Rmd 脚本:
Rscript -e "require( 'rmarkdown' ); render('/home/sms/Dokumenty/R/test.Rmd', 'html_document')"
没有任何问题。有效。
所以我创建了bash脚本
#!/bin/bash
Rscript -e "require('rmarkdown'); render('/home/sms/Dokumenty/R/test.Rmd', 'html_document')"
并更改了 chmod 755 test.sh
也很有魅力。
但是当放入 Cron 文件时(管理员和用户):
28 18 * * * sh /home/sms/Dokumenty/R/test.sh
没用
知道我做错了什么吗?
简化,简化,再简化。
首先,我将其设为 Rscript,可能名为 renderTest.R
#!/usr/bin/Rscript
library(rmarkdown)
setwd("/home/sms/Dokuments/R")
render("test.Rmd") # I usually use default arguments
其次,使脚本可执行(chmod 0755 renderTest.R
)。
三、测试脚本。如果你可以 运行 像你一样,一个 cron 作业 运行ning 你也应该这样做。
第四,添加cronjob 运行ning作为you拥有同样的权利
编辑 我刚刚修正了一个从您那里复制的错字:Documents/
而不是 Documenty/
.
我也有同样的问题。
但如果您尝试使用 knitr::knit2html 而不是 rmarkdown::render
,它会起作用关于为什么
我遇到了同样的问题。 问题是因为我 运行 将 Rscript 设置为 root,但 Rscript 应该 运行 作为 souza,当前用户。 为了解决这个问题,我为用户 souza "sudo crontab -u souza -e" 编辑了 crontab,Rscript 是 运行 作为 souza 而不是 root。 现在正在运行