[英]Crontab doesn't execute R script
I'm trying to setup a Cron job on my system by adding the following line我正在尝试通过添加以下行在我的系统上设置 Cron 作业
17 12 * * * Rscript ~/path/to/file/script.R > ~/output_`date +\%d\%m\%y`.txt 2>&1
yet, I cannot see the file the output is being written to.但是,我看不到正在写入输出的文件。 I've consulted the following answers, but to no avail:
我查阅了以下答案,但无济于事:
Why did my crontab not trigger 为什么我的 crontab 没有触发
CronJob not running CronJob 未运行
When I run the following command on the terminal:当我在终端上运行以下命令时:
Rscript ~/path/to/file/script.R > ~/output_`date +\%d\%m\%y`.txt 2>&1
I get the output file as expected.我按预期得到输出文件。 I also added the following line to crontab:
我还在 crontab 中添加了以下行:
* * * * * echo hi > ~/output.txt 2>&1
and it works just fine.它工作得很好。 I'm not sure what is wrong with the first command.
我不确定第一个命令有什么问题。 Any help would be appreciated.
任何帮助,将不胜感激。 Thanks.
谢谢。
Try Below trick, Create one script script.sh like below -尝试以下技巧,创建一个脚本 script.sh,如下所示 -
cat script.sh
Rscript ~/path/to/file/script.R > ~/output_$(date +\%d\%m\%y).txt 2>&1
And then create below entry in crontab.然后在 crontab 中创建以下条目。
17 12 * * * /bin/bash /path/to/script.sh
我解决了这个问题通过更换Rscript
在我的crontab用/usr/local/bin/Rscript
(或任何你RSCRIPT所在-做which Rscript
找出)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.