Raspbian/Linux 如何将 R 脚本作为 crontab 运行? [英] Raspbian/Linux how can I run my R scripts as crontabs?

查看:12
本文介绍了Raspbian/Linux 如何将 R 脚本作为 crontab 运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个非常基本的问题,但我是新手:我正在尝试在我的 Raspberry Pi 上安排一些 Rscript,但一直失败.首先它什么也没做,现在它说它不能运行我的 crontab,因为它们有错误的命令".

This is probably a very basic question but I'm new to this: I'm trying to schedule some Rscript on my Raspberry Pi but keep failing with it. First it didn't do anything and now it says that it can't run my crontabs because they have 'bad commands'.

我尝试了两种不同的风格:

I have tried in two different styles:

sudo crontab -e

17**** cd [/home/pi/R/projects] && Rscript scraper_srf.R
20**** cd [/home/pi/R/projects] && Rscript scraper_srf.R
29**** cd [/home/pi/R/projects] && Rscript 20min_retry_update_08_06_2020.R
30 21*** cd [/home/pi/R/projects] && Rscript soweitsieht_update_10_06_2020.R

sudo crontab -e

32**** Rscript /home/pi/R/projects/scraper_srf.R
20**** Rscript /home/pi/R/projects/scraper_blick.R
29**** Rscript /home/pi/R/projects/20min_retry_update_08_06_2020.R
3021*** Rscript /home/pi/R/projects/soweitsieht_update_10_06_2020.R

感谢您的帮助

推荐答案

以下方法对我有用:

1) 制作一个 shell 脚本 (myScript.sh) 和你的 R 文件

1) make a shell script (myScript.sh) along with your R files

#!/bin/sh
cd /myScriptDir
Rscript myScript.R

2) 测试shell脚本

2) test the shell script

cd /myScriptDir
sh myScript.sh

3) 编辑 crontab :

3) edit crontab :

# m h  dom mon dow   command
0 8 * * * sh /myScriptDir/myScript.sh

正如@amatsuo_net 所提到的,* 之间的空格是必要的

as mentionned by @amatsuo_net, space between * is necessary

这篇关于Raspbian/Linux 如何将 R 脚本作为 crontab 运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆