tcshpbs

Using name of BASH script as input argument


I have a large number of .pbs files that I want to submit to a remote cluster. I want to be able to name the .pbs file something like "param1_123_param2_45.pbs", and then feed them into the ARGS for a Julia code. Below is an example .pbs of what I'm trying to do:

1 #!/bin/tcsh 
2 #PBS -l mem=10gb,nodes=1:ppn=2,walltime=1:00:00
3 #PBS -j oe
4 #PBS -o ./log/julia.${PBS_JOBID}.out
5 #PBS -t 1-3
6 
7 module load julia/1.5.1 python/3.8.1
8 
9 cd path/to/file  
10 
11 julia Example.jl 123 45

Except 123 & 45 are replaced by some general terms given in the name of the .pbs file. Is there an easy way to do this?


Solution

  • You can use AWK. For example, content of file param1_123_param2_45.pbs:

    PARAM1=$( echo ${0%%.pbs} | awk -F "_" '{print $2}' )
    PARAM2=$( echo ${0%%.pbs} | awk -F "_" '{print $4}' )
    echo "Filename: $0"
    echo "Param 1: $PARAM1"
    echo "Param 2: $PARAM2"
    

    Running: bash param1_123_param2_45.pbs

    Output:

    Filename: param1_123_param2_45.pbs
    Param 1: 123
    Param 2: 45