执行 r 脚本的 cron 作业不起作用 [英] cron job to execute r script not working
问题描述
我是 cron 的新手.我想使用 cron 定期执行 r 脚本.我刚刚将作业添加到 crontab 以检查它是否有效.但不幸的是,没有任何效果.我编写了一个测试脚本,并在 cron 作业中每 5 分钟安排一次.
I am new to cron. I want to execute r script on regular basis using cron. I just added the job to crontab to check if it is working. But unfortunately, nothing is working. I wrote a test script and scheduled it for every 5 mins in cron job.
这是测试 R 脚本:
print('HI')
定时任务:5 * * * * sudo Rscript/path/to/script/test.R
但是当我从终端执行它时,它工作正常.
but when I execute it from terminal, it works fine.
终端命令:sudo Rscript/path/to/script/test.R
如果我在这里遗漏了什么,请告诉我.我试图让它每 5 分钟运行一次.
Please tell me if I am missing something here. I was trying to make it run for every 5 minutes.
推荐答案
Change the permissions 文件/path/to/script/test.R 并确保它有执行权限您尝试提交 cronjob 的用户.
Change the permissions of the file /path/to/script/test.R and make sure, it has execution permissions to the user you are trying to submit the cronjob.
chmod 777/path/to/script/test.R
或者,您也可以尝试下面提到的方法
Alternately, you can also try below mentioned ways also
创建一个 shell 文件(即 sample.sh)并将以下代码放入其中.Rscript/path/to/script/test.R ,并按如下所述安排 cron 作业.
Create a shell file (i.e., sample.sh) and place the following code in it. Rscript /path/to/script/test.R , and schedule the cron job as mentioned below.
5 * * * */path/to/script/sample.sh
这篇关于执行 r 脚本的 cron 作业不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!