繁体   English   中英

使用R Markdown将bash脚本作为Cron作业运行

[英]Running bash script as Cron job with R Markdown

我想尝试如何从R markdown文件渲染html,但是从作为Cron作业运行的bash脚本中渲染。 我不知道为什么一切正常,除了作为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作业。

四,添加的cronjob运行, 有同样的权利。

编辑我刚刚修复了我从你那里复制过的拼写错误: Documents/ not Documenty/

我有同样的问题。

但是如果你尝试使用knitr :: knit2html而不是rmarkdown :: render它会工作

想法为什么

我有同样的问题。 问题是因为我以root身份运行Rscript,但Rscript应该作为souza运行,当前用户。 为了解决这个问题,我为用户搜索“sudo crontab -u souza -e”编辑了crontab,并且Rscript作为souza而不是root运行。 现在它正在运作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM