3

This is an extension of a previous question I asked:

Using name of BASH script as input argument

My goal is to write a BASH script which takes the arguments from the file's name and uses them as inputs for a Julia code I'm writing, and then submit the BASH script to a remote cluster. Using @AndriyMakukha's solution, I was able to write the following script through Torque:

#!/bin/bash
 
#PBS -l mem=10gb,nodes=1:ppn=2,walltime=1:00:00
#PBS -N ES_100_20_100
#PBS -j oe
#PBS -o ./log/julia.${PBS_JOBID}.out

module load julia/1.5.1 python/3.8.1
 
PARAM1=$( echo ${0%%.pbs} | awk -F "_" '{print $2}' )  
PARAM2=$( echo ${0%%.pbs} | awk -F "_" '{print $3}' )  
PARAM3=$( echo ${0%%.pbs} | awk -F "_" '{print $4}' )  
PARAM4=$( echo ${0%%.pbs} | awk -F "_" '{print $5}' ) 
PARAM5=$( echo ${0%%.pbs} | awk -F "_" '{print $6}' )  
 
echo "Param 1: $PARAM1"
echo "Param 2: $PARAM2"
echo "Param 3: $PARAM3"
echo "Param 4: $PARAM4"
echo "Param 5: $PARAM5"

cd path/to/code 
julia Example.jl $PARAM1 $PARAM1 $PARAM2 $PARAM3 $PARAM4 $PARAM5 

This script (called "Example_1_2_3_4_5.pbs") prints the different parameters from the filename to the output file, and then runs the Julia code with said parameters as the ARGS. When I run this on the local machine, it works great. When I submit the code to the cluster via qsub, I get the following error in the output file:

Param 1: priv/jobs/3574314-1.orion.cm.cluster.SC
Param 2:
Param 3:
Param 4:
Param 5:
ERROR: LoadError: ArgumentError: invalid base 10 digit 'p' in "priv/jobs/3574314-1.cluster_name.cm.cluster.SC"

Obviously, the code isn't reading the parameters correctly; i.e., it returns the name of the job, not the name of the BASH file itself. This is obvious because

echo ${0%%.pbs}

returns

/cm/local/apps/torque/var/spool/mom_priv/jobs/3574314-1.orion.cm.cluster.SC

How can I get the name of the pbs file itself if I submit to cluster, seeing as ${0%%.pbs} doesn't work?

8
  • What do you see if you add echo "$*" at the beginning of your script? Can you elaborate on what you mean by "submit the code to the cluster via qsub"? Commented Jan 16, 2021 at 23:29
  • @ShaneBishop It doesn't print anything when I try that. I mean when I just run "qsub script_name.pbs", I get the error described above. When I just run "bash script_name.pbs", it runs fine. Commented Jan 16, 2021 at 23:36
  • 1
    What about using -v variable_list option of qsub and adding those variables yourself when submitting the job? Commented Jan 16, 2021 at 23:41
  • 1
    Have you looked at stackoverflow.com/questions/26487658/…? You can use -F or, if -F is not available, it might be possible with -v. Commented Jan 16, 2021 at 23:44
  • 1
    @Socowi yes but perhaps you could have a "proxy" bash file that would check the filename and than build a qsub command with the -v parameter? Commented Jan 17, 2021 at 1:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.