It is possible to provide parameters to the sbatch command:
sbatch jobscript.sh parameter1 parameter2
When the job starts, it will start the jobscript.sh as “jobscript.sh parameter1 parameter2”. In your (Bash) script you can access the parameters in the usual way, e.g. with $1 and $2 to get the individual values or $* to get all parameter values.
Example for a Python script:
#!/bin/env python import sys print('Number of arguments:', len(sys.argv), 'arguments.') print('Argument List:', str(sys.argv))
This file should be saved as python_passing_parameters.py, so that it can be run by the following batch script:
#!/bin/bash #SBATCH --time=00:01:00 #SBATCH --nodes=1 #SBATCH --ntasks=1 #SBATCH --job-name=python_passing_parameters #SBATCH --mem=500 module purge module load Python/3.10.4-GCCcore-11.3.0 python python_passing_parameters.py $*
You can now submit the job with “sbatch jobscript.sh 1 2 a b”, and your input parameters (1 2 a b) will be forwarded to the Python script.