Question

So I have an R file that I would like to schedule to run every 10 minutes. I have created an entry for the file in crontab through the Terminal (using crontab -e). As so:

*/10    *       *       *       *       root    /Users/A/Documents/code/r/r_file.r

When I run the commands in the console it executes as designed and I can verify records in the database. However, with this cron setup I am not getting the end result.

I did get the following error message:

/bin/sh: root: command not found

I am sure this is a total rookie question as I do not have much experience with crontab. Any advice is greatly appreciated.

Thanks,

Jason

Was it helpful?

Solution

Is Rscript is in your path? More importantly, is it in path of the user running the commamd, here root? (Also consider running the command as you).

If so, try

*/10 * * * *      yourlogin    Rscript /Users/..../file.R

Test your understanding of crontab with a simpler job that just stores timestamps, maybe

*/10 * * * *      yourlogin    date > /tmp/testcrontab.txt

Once you have that mastered, run a simple R script and then move on to your real script.

OTHER TIPS

The "root" part of you crontab line is what's screwing you up. When you use crontab -e, you should not specify the user because all the commands run as your current user (i.e. the user you are logged in as when you run crontab -e).

Also, you should always use full paths in your crontab.

The cron line should look like this:

*/10 * * * * /path/to/Rscript /Users/A/Documents/code/r/r_file.r

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top