如何在 Mac Snow Leopard 上的 crontab 中安排 R 脚本?
所以我有一个 R 文件,我想安排它每 10 分钟运行一次。我已通过终端(使用 crontab -e)在 crontab 中为该文件创建了一个条目。因此:
*/10 * * * * root /Users/A/Documents/code/r/r_file.r
当我在控制台中运行命令时,它会按设计执行,并且我可以验证数据库中的记录。然而,通过这个 cron 设置,我没有得到最终结果。
我确实收到以下错误消息:
/bin/sh: root: command not found
我确信这完全是菜鸟问题,因为我对 crontab 没有太多经验。非常感谢任何建议。
谢谢,
杰森
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
crontab 行的“根”部分是让你陷入困境的原因。使用 crontab -e 时,不应指定用户,因为所有命令都以您当前的用户身份运行(即运行 crontab -e 时登录的用户) >)。
另外,您应该始终在 crontab 中使用完整路径。
cron 行应如下所示:
*/10 * * * * /path/to/Rscript /Users/A/Documents/code/r/r_file.r
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 runcrontab -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
Rscript
在您的路径中吗?更重要的是,它是否位于运行命令的用户的路径中,这里是 root? (另请考虑按照您的方式运行该命令)。如果是这样,请尝试
使用仅存储时间戳的更简单的作业来测试您对 crontab 的理解,也许
一旦您掌握了它,就可以运行一个简单的 R 脚本,然后继续执行真正的脚本。
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
Test your understanding of
crontab
with a simpler job that just stores timestamps, maybeOnce you have that mastered, run a simple R script and then move on to your real script.