问题
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?
来源:https://stackoverflow.com/questions/65755537/using-parameters-from-bash-file-name-as-arguments-for-julia-script-on-cluster