在启动时运行R脚本

编程入门 行业动态 更新时间:2024-10-26 22:18:01
本文介绍了在启动时运行R脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

首先,这可能需要移至超级用户.我无法确定哪个场所更好.

First of all, this may need to be moved to superuser. I couldn't decide which venue was better.

我正在尝试编写一个将在引导/重新引导时运行的R脚本,并将该计算机添加到 doRedis 工作人员. (doRedis是 foreach 后端).

I am trying to write an R script that will run at boot/reboot and add that machine to a pool of doRedis workers. (doRedis is a foreach backend).

这是我的R脚本〜/Rworker.R"

Here is my R script, "~/Rworker.R"

#Define Parameters require(multicore) Host <- 'ip_of_doRedis_Server' cores <- multicore:::detectCores() TO <- 24*3600 #Start Workers require('doRedis') startLocalWorkers(cores,'jobs',host=Host,port=6379, timeout = TO)

我可以使用以下命令从命令行运行此脚本 sudo R CMD BATCH ~/Rworker.R ~/RLog.

I can run this script from the command line, using the command sudo R CMD BATCH ~/Rworker.R ~/RLog.

接下来,我编写了一个Shell脚本来运行R脚本,标题为"/etc/init.d/StartWorkers.sh"

Next, I wrote a shell script to run the R script, titled "/etc/init.d/StartWorkers.sh"

#!/bin/sh sudo echo "Starting R workers" sudo R CMD BATCH ~/Rworker.R ~/RLog

我使用chmod +x StartWorkers.sh使此Shell脚本可执行.当我运行./StartWorkers.sh时,一切正常,R会话启动,并且工作线程被添加到池中.

I made this shell script executable, using chmod +x StartWorkers.sh. When I run ./StartWorkers.sh everything works great and the R session starts up and the workers get added to the pool.

现在,我需要这个shell脚本在启动/重新引导机器时运行,所以我键入 update-rc.d StartWorkers.sh defaults.该命令似乎可以工作,但是出现以下警告: 'update-rc.d:警告:/etc/init.d/StartWorkers.sh缺少LSB信息'

Now, I need this shell script to run when I boot/reboot the machine, so I type update-rc.d StartWorkers.sh defaults. This command appears to work, but I get the following warning: 'update-rc.d: warning: /etc/init.d/StartWorkers.sh missing LSB information'

但是,使用rcconf进行的检查确认"StartWorkers.R"在启动列表上.

However, a check with rcconf confirms that "StartWorkers.R" is on the startuplist.

但是,当我重新启动计算机时,脚本无法运行.我究竟做错了什么? Shell脚本可以从命令行正常运行,但是当我尝试在启动时运行它时会失败.

However, when I reboot the machine, the script fails to run. What am I doing wrong? The shell script runs fine from the command line, but fails when I try to run it at startup.

/好的,按照Dirk的回答,我安装了littler,并将'StartWorkers.sh'更改为以下内容:

/ ok, per Dirk's answer, I installed littler, and changed 'StartWorkers.sh' to the following:

#! /usr/bin/r #Define Parameters require(multicore) Host <- 'zachec2.dyndns' cores <- multicore:::detectCores() TO <- 24*3600 #Start Workers require('doRedis') startLocalWorkers(cores,'jobs',host=Host,port=6379, timeout = TO)

但是当我运行它时,会得到以下输出:

But when I run it, I get the following output:

Loading required package: utils Loading required package: multicore Warning message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called 'multicore' Error in loadNamespace(name) : there is no package called 'multicore' Calls: ::: ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous> Execution halted

我知道我的系统上已安装多核!

I know I have multicore installed on my system!

/我必须将所有R包都移到cd /usr/lib/R/site-library,现在littler shell脚本可以工作了.我将脚本添加到/etc/rc.local,它可以完美启动!

/ I had to move all my R packages to cd /usr/lib/R/site-library and now the littler shell script works. I added the script to /etc/rc.local and it starts up perfectly!

推荐答案

这是一个R问题,一个关于Ubuntu sysadmining问题的问题.这里有几点:

This is a bit of an R question, and a bit on an Ubuntu sysadmining question. here are a few points:

  • 对于简单的启动任务,我建议仅使用/etc/rc.local即可在其中添加作业.

  • For simple start-up tasks, I recommned just using /etc/rc.local where you can append you jobs.

    我只是不喜欢R CMD BATCH,这就是为什么杰夫·霍纳和我写了 littler ,可为您提供/usr/bin/r以及更简单的R脚本. R本身也给您Rscript;比R CMD BATCH更好.

    I just don't like R CMD BATCH which is why Jeff Horner and I wrote littler which gives you /usr/bin/r and much easier R scripting. R itself also gives you Rscript; either one is preferable over R CMD BATCH.

    要测试脚本,只需以root身份运行它们.一旦完成操作,请将其添加到/etc/rc.local.

    To test scripts, just run them as root. Once theyw ork, add them to /etc/rc.local.

    希望这会有所帮助. r-sig-debian列表也是Ubuntu/Debian技巧的很好来源.

    Hope this helps. The r-sig-debian list is a good source of Ubuntu / Debian tips too.

  • 更多推荐

    在启动时运行R脚本

    本文发布于:2023-11-05 06:21:27,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1560134.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:启动时   脚本

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!