Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
462 views
in Technique[技术] by (71.8m points)

cron - Raspbian/Linux how can I run my R scripts as crontabs?

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

and

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

thx for your help

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The following approach worked for me :

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

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

2) test the shell script

cd /myScriptDir
sh myScript.sh

3) edit crontab :

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

as mentionned by @amatsuo_net, space between * is necessary


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...