Search code examples
bashhpcpbs

Running multiple jobs with unique name using qsub


I have a bunch of text (input) files with the name

foo_bar_abc_1_01_geh_file.in
foo_bar_abc_1_02_geh_file.in
foo_bar_abc_1_03_geh_file.in
...
...
foo_bar_abc_1_1000_geh_file.in

I use following command to run these multiple jobs (in a HPC cluster)

for f in foo*.in; do qsub -N test -v infile=$f run.pbs

The problem in this one-line script is that the Job Name (in the cluster) is same for all the jobs in queue (i.e., test is the name for all jobs).

I would like to name each job something like test01, test02, test03...test1000 (numbers taken/extracted from the corresponding file names. For example,

   #For foo_bar_abc_1_01_geh_file.in, the Job Name should be test01,   
   #For foo_bar_abc_1_02_geh_file.in, the Job Name should be test02,   
   #For foo_bar_abc_1_100_geh_file.in, the Job Name should be test100,
   etc.

How to do this is bash?


Solution

  • You can use cut like

    for f in foo*.in; do qsub -N test$(echo $f|cut -d_ -f5) -v infile=$f run.pbs; done
    

    where

    • -d_ sets delimiter character to _ and
    • -f5 select only 5th column (i.e. the number of the job)