繁体   English   中英

如何在具有“for”和“R”代码的服务器中运行 bash 脚本,我可以退出终端并且不会终止进程?

[英]How do I run a bash script in a server with `for` and `R` code that I can exit the terminal and does not kill the process?

上下文:我正在通过 R 运行模拟,每次重复花费的时间太长,并且消耗 memory。 因此,我需要在每次重复时在 R 中启动另一个 session,这样我就不会遇到 memory 问题。

我的问题:执行我的 bash 脚本后,我从终端exit ,当前重复成功完成,但下一个没有开始(我通过ssh在服务器上运行它)。

我做了什么:

compoisson.sh bash 脚本:

#!/bin/bash

for rho in $(seq 1 3); do
    for rep in $(seq 1 200); do
         Rscript Teste.R $rho $rep
    done
done

在终端中(通过 ssh user@domain...进入后):

chmod +x compoisson.sh
sh compoisson.sh &
exit

我的Teste.R脚本(内容不重要,可能是空文件):

rm(list=ls())
library(TMB)
# library(TMB, lib.loc = "/home/est/bonat/nobackup/github")
model <- "04_compoisson_bi" #1st try
compile(paste0(model, ".cpp"), flags = "-O0 -ggdb")
dyn.load(dynlib(model))
## Data simulation -------------------------------------------------------------
nresp <- 2; beta1 <- log(7);beta2 <- log(1.5);nu1 <- .7
nu2 <- .7;n <- 50;s2_1 <- 0.3;s2_2 <- 0.15;true_rho <- 0
sample_size <- 1000
openmp(4)
args <- commandArgs(TRUE)
rhos <- c(-.5,0,.5)
true_rho <- rhos[abs(as.numeric(args[1]))]
j <- abs(as.numeric(args[2]))
seed <- 2109+j
res_neg <- simulacao(nresp, beta1, beta2, true_rho, s2_1, s2_2, seed, sample_size = sample_size, model, nu1=nu1, nu2=nu2, j = j) # 1 by time
saveRDS(res_neg, file = paste0(getwd(), "/Output/output_cmp_rho", true_rho, "n", sample_size, "j", j, ".rds"))

一个重要的细节是我需要通过ssh在外部服务器上运行它。 我在我的电脑上用一个空的.R文件做了一个小测试,我也能看到通过htop创建的不同进程。 在服务器上,它没有发生。

我也尝试nohup运行我的compoisson.sh文件( question1question2 ),但我没有任何成功。 我的测试:

nohup compoisson.sh & 
ignoring the entrance and attaching the output to 'nohup.out'
nohup: failt to execute the command 'compoisson.sh': File or directory does not exists.

我究竟做错了什么?

解决了nohup./compoisson.sh &而不是sh compoisson.sh &

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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