Ubuntu: Very Simple RScript Cronjob Ubuntu


I have been trying to get a very simple R script (RScript) to run every minute by employing a cronjob; I am on an Ubuntu 16.04 server. The R script reads an integer between 0-59 from 1 .csv, increments it by 1, and then writes it to an output .csv. So there are three files:

  1. simpleRScript.R
  2. input.csv
  3. output.csv


 # simpleRScript.R       temp_output <- read.csv("output.csv", stringsAsFactors = FALSE, header = TRUE)       input <- read.csv("input.csv", stringsAsFactors = FALSE, header = TRUE)       output <- input$value[which(input$value == temp_output$value[1])+1]       if(output == 60, output <- 0)       write.csv(output, file = "output.csv", row.names = FALSE)  


 value,   0,   1,   2,   ...,   59  


 value,   0  

I stored these three files in a folder, cronTest such that they are in:


Then in the command line, I did the following:

 #   crontab -e  

And then at the bottom, I typed:

 * * * * * RScript /home/ubuntu/cronTest/simpleRScript.R  

So why when I type:

 less output.csv  

do I not see an incremented value every minute?

Thank you for helping me set up my first RScript cronjob!


ANSWER (thanks to steeldriver in comments)

Change the cronjob command to

 * * * * * cd /home/ubuntu/cronTest/ && /usr/lib/R/bin/Rscript simpleRScript.R  

For R users, the Rscript command on ubuntu 16.04 LTS when installed is /usr/lib/R/bin/Rscript

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »