How to run an R script in crontab

前端 未结 3 1706
不知归路
不知归路 2021-01-15 06:44

Using crontab -e I\'ve tried:

* * * * *  Rscript /home/.../file.r
* * * * * /usr/lib/R/bin/Rscript /home/.../file.r
* * * * * /usr/bin/Rscript /home/.../file         


        
相关标签:
3条回答
  • 2021-01-15 07:28

    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.

    0 讨论(0)
  • 2021-01-15 07:31

    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

    0 讨论(0)
  • 2021-01-15 07: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 * * * * *

    0 讨论(0)
提交回复
热议问题