0

The following is my very simple Rscript called test.R that I want to run every minute

print("Hello, World!")

and I would like to automate this script in the hopes that I can do the same for future scripts. I use the crontab -e call and add the following:

* * * * * Rscript home/<username>/test.R

which fails to produce any results.

Per the examples of cron job to execute r script not working and Schedule a Rscript crontab everyminute, I have made the following variations in the crontab code

* * * * * Rscript "home/<username>/test.R"
* * * * * usr/bin/Rscript home/<username>/test.R
* * * * * usr/bin/Rscript "home/<username>/test.R"
* * * * * cd home/<username>/ && Rscript test.R
* * * * * cd home/<username>/ && usr/bin/Rscript test.R

all of which do nothing. I have also created a script called myScript.sh which contains Rscript /home/<username>/test.R, and tried assigning the task * * * * * home/<username>/myScript.sh all to no avail.

I have made sure to run chmod +x to make my files executable beforehand, and simply typing Rscript test.R produces my desired results.

What else can I do to make this work? Is there some issue with me running Ubuntu Server 18.04 vs running the desktop version?

Update

I have run all the above variations, with a / before home and usr. I have also switched to trying ~/test.R but I still get no results.

Community
  • 1
  • 1
Jacob
  • 406
  • 3
  • 19
  • 1
    Put a slash in front of `home`, ie make it `/home//test.R` or, equally, `~/test.R`. – Dirk Eddelbuettel Nov 14 '19 at 00:44
  • I tried what you have suggested, and updated my question to reflect that. It still isn't working. Is there some sort of command that I have to run anytime I update a cron job? – Jacob Nov 14 '19 at 01:03
  • This is elementary Unix, and there will be several hundred near-identical questions here, and the unix stackexchange site and the sysadmin stackexchange site. Do `date > /tmp/filestamp.txt` and then you see when it ran. Build up from there. – Dirk Eddelbuettel Nov 14 '19 at 01:58

1 Answers1

1

Is it possible that it is running correctly and the results are not being captured? Cron won't return results to active terminal.

The following worked for me on an Ubuntu Server 16.04

First, confirmed that the test script return was expected when run from Rscript terminal:

root@mytester:~/myrscripts# Rscript test.R

returns

  [1] "Hello, World!"

Second, setup cron job via:

crontab -e

entered this line

* * * * * Rscript ~/myrscripts/test.R >> ~/mycronlog.log

notice I am piping results to a log (appending)

Third, checked log after a few minutes:

root@mytester:~# cat mycronlog.log 
[1] "Hello, World!"
[1] "Hello, World!"
[1] "Hello, World!"
[1] "Hello, World!"
[1] "Hello, World!"
  • I completely spaced that I had to assign the output to a file. This also successfully works when needing to run my Rscript. – Jacob Nov 14 '19 at 04:33