bnosac / cronR

A simple R package for managing your cron jobs.
Other
290 stars 38 forks source link

unexpected path behavior under linux #19

Closed cawthm closed 5 years ago

cawthm commented 5 years ago

For some reason, my repository path isn't getting preserved when cron is run from a crontab set by this very useful package.

Eg, given a toy test script file:

###test_script.R
cat(getwd())
###

The Rscript repository path: launch & log location dialog box looks correctly populated, eg it shows: /home/me/my_script_folder, where test_script.R lives

if I test it with run once test, eg:

nohup /usr/lib/R/bin/Rscript '/home/me/my_script_folder/test_script.R' >> '/home/me/my_script_folder/test_script.log' 2>&1 &

I see
/home/me/my_script_folder in the log file, as expected.

however, if I set a CRON job for test_script.R say, every minute

eg:

$crontab -e
0-59 * * * * /usr/lib/R/bin/Rscript '/home/me/my_script_folder/test_script.R

the cat'd path is just /home/me in the log file, dropping the project folder /my_script_folder

I'm running CronR 0.4.0 Under Rstudio 1.2.1335 With R 3.6.0 on Ubuntu 18.04 bash is default shell

jwijffels commented 5 years ago

That's how cron works. It starts the script from a different directory. You need to change your R code, Learn how to use environment variables to provide a path.

cawthm commented 5 years ago

Thanks. For some reason, this isn't how it worked on mac os; ie the script wasn't portable to the new linux box w/ identical cronR setup steps.

jwijffels commented 5 years ago

cron runs the job as the user under which you scheduled the job. In no way this will be /home/me/my_script_folder, neither on mac or on linux

cawthm commented 5 years ago

You are correct, having just tried to replicate on my mac. My script paths were slightly different on the two machines. Thank you for your help.