Pass command line arguments via sbatch

后端 未结 6 1195
我寻月下人不归
我寻月下人不归 2021-01-31 02:44

Suppose that I have the following simple bash script which I want to submit to a batch server through SLURM:

#!/bin/bash

#SBATCH -o \"outFile\"$1\".txt\"
#SBATC         


        
6条回答
  •  無奈伤痛
    2021-01-31 03:33

    The lines starting with #SBATCH are not interpreted by bash but are replaced with code by sbatch. The sbatch options do not support $1 vars (only %j and some others, replacing $1 by %1 will not work). When you don't have different sbatch processes running in parallel, you could try

    #!/bin/bash
    
    touch outFile${1}.txt errFile${1}.txt
    rm link_out.sbatch link_err.sbatch 2>/dev/null # remove links from previous runs
    ln -s outFile${1}.txt link_out.sbatch
    ln -s errFile${1}.txt link_err.sbatch
    
    #SBATCH -o link_out.sbatch
    #SBATCH -e link_err.sbatch
    
    hostname
    # I do not know about the background processing of sbatch, are the jobs still running
    # at this point? When they are, you can not delete the temporary symlinks yet.
    
    exit 0
    

    Alternative: As you said in a comment yourself, you could make a masterscript. This script can contain lines like

    cat  exampleJob.sh.template | sed -e 's/File.txt/File'$1'.txt/' > exampleJob.sh
    # I do not know, is the following needed with sbatch?
    chmod +x exampleJob.sh
    

    In your template the #SBATCH lines look like

    #SBATCH -o "outFile.txt"
    #SBATCH -e "errFile.txt"
    

提交回复
热议问题