bash 如何在qsub中指定错误日志文件和输出文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9096959/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 21:37:04  来源:igfitidea点击:

how to specify error log file and output file in qsub

bashcluster-computingqsubsungridengine

提问by d.putto

I have a qsub script as

我有一个 qsub 脚本

#####----submit_job.sh---#####
    #!/bin/sh
    #$ -N job1
    #$ -t 1-100
    #$ -cwd
    SEEDFILE=/home/user1/data1
    SEED=$(sed -n -e "$SGE_TASK_ID p" $SEEDFILE)
    /home/user1/run.sh $SEED 

The problem is-- it puts all error and output files (job1.eJOBID & job1.oJOBID) to the same directory from where I am running qsub submit_job.sh while I want to save these file (output and error log file in same different place (specified as $SEED_output). I tried to change the line as

问题是——它将所有错误和输出文件(job1.eJOBID 和 job1.oJOBID)放在我运行 qsub submit_job.sh 的同一目录中,而我想保存这些文件(输出和错误日志文件在相同的不同位置(指定为 $SEED_output)。我尝试将行更改为

/home/user1/run.sh $SEED -o $SEED_output

But it didn't work. Any suggestion ?? How can I specify path and name of default output and error log file ??

但它没有用。任何建议?如何指定默认输出和错误日志文件的路径和名称?

回答by Andy

Typically error and output files are given as pbs directives in the qsub script or as command line options to the qsub script like so:

通常,错误和输出文件作为 qsub 脚本中的 pbs 指令或作为 qsub 脚本的命令行选项提供,如下所示:

#! /bin/bash
#PBS -q queue_name
#PBS -A account_name
#PBS -l nodes=12:ppn=12
#PBS -l walltime=18:00:00
#PBS -e /mypath/error.txt
#PBS -o /mypath/output.txt

or as a command line option to qsub like so:

或作为 qsub 的命令行选项,如下所示:

qsub -o /mypath/output.txt -e /mypath/error.txt submit_job.sh

With the first option I don't think you can use a variable as the shell won't look at lines that are commented. Plus I think PBS deals with the commented lines before the shell would. If you know the path when you're invoking qsub, you could try the second option. Alternatively you could try simply redirecting the output and error in the script itself:

对于第一个选项,我认为您不能使用变量,因为 shell 不会查看注释的行。另外,我认为 PBS 在 shell 之前处理注释行。如果您在调用 qsub 时知道路径,则可以尝试第二个选项。或者,您可以尝试简单地重定向脚本本身的输出和错误:

/home/user1/run.sh $SEED > ${SEED}/output.txt 2> ${SEED}/error.txt

The third option is probably the easiest. Output and error files might still be created in the run directory, though they'd likely be empty.

第三种选择可能是最简单的。输出和错误文件可能仍会在运行目录中创建,尽管它们可能是空的。

回答by Andy

At first glance, you need brackets around your variable in the -o declaration.

乍一看,您需要将 -o 声明中的变量括起来。

/home/user1/run.sh $SEED -o ${SEED}_output

Otherwise bash is looking for a variable called ${SEED_output} which doesn't exist.

否则 bash 正在寻找一个不存在的名为 ${SEED_output} 的变量。