简体   繁体   中英

Crontab Redhat 8: Crontab will not run an R script that works perfectly otherwise

I'm currently trying to run a R file every minute through crontab. The R file take in a file from the previous directory and inputs into a sub-directory. If I just./script.R the command will run fine, read and output all the data 100% accurately. However, in crontab it will not even run. I have tried a sample crontab to test if it was my crontab not working first, I wrote

* * * * * /bin/echo "foobar" >> /home/a/t/test.log

This command would correctly send foobar to the log. However when I did

* * * * * /home/a/t/script.R >> /home/a/t/test.log

I would get no results within the test.log, nor would I get results in the subdirectory it should store in after being ran. I also did the script another way to see if the * were causing issues

*/1 * * * * /home/a/t/script.R >> /home/a/t/test.log

This also did not give any results. After some research what I can understand is that there is likely an issue with paths. So to try to counteract that I did a cd command along with the R command as such:

 */1 * * * *  cd /home/a/t/ && /home/a/t/script.R >> /home/a/t/test.log

Still, however, this has given 0 output. If I type grep CRON /var/log/cron I see cron trying to run the lines every minute, but again no output found anywhere, I dont think it is running and I can't understand why not. Also in terms of path for the R script itself, within the R script I have the first line written something like

#!/bin/env Rscript -S --vanilla

which allows me to./script.R and run it after a chmod as well. This exact crontab commands also worked for me on my other laptops ubtunu vm, which is causing more confusion.

The command for running Rscript should be

Rscript path/to/Rscript.R

Please test the command by running it in your terminal. Once it run perfectly fine then just take the whole command and put it in crontab.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM