How to run an R script in crontab

北慕城南 提交于 2019-12-02 00:42:45

You'll need to have the full path in your foo.sh:

sudo R CMD BATCH /home/.../file.r

I should also add that the first version worked for me, although I set it to a specific time rather than * * * * *

For what it is worth here is CRANberries entry which has worked (multiple times) every day for 5+ years:

# every few hours, run cranberries
11 */2 * * *    edd     ~/cranberries/cranberries.r

Of note here are

  1. The time specification, here 11 mins past the hour every two hours
  2. The user
  3. The complete path, using 'globbing' to expand ~ to $HOME for edd

and after that you just have to make sure the script is actually executable. Whether you use Rscript, littler or R BATCH CMD does not matter.

in my user level crontab I run a R script to collect tweets from various sources.

I used: crontab -u myusername -e added this to the end of my crontab file

0 0 * * * /home/bob/Documents/SWtweets/tweetbash.sh

I ran it as a user vs root, don't what difference it makes, but it only worked for me when I ran it at user level.

below is what I put in my tweetbash.sh shell script, which tells the bash program to run the R script located at the path indicated.

#! /bin/bash R CMD BATCH /home/bob/Documents/SWtweets/tweets.R

did chmod +x tweetbash.sh

it works for my purposes.

Bob

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!