bashshellsingularity-containerapptainer

Running a command within a launched shell within an apptainer instance


I'm working towards setting up a script for batch submission to an HPC system which uses software in an apptainer image. Here's what I have in mind:

apptainer run container.sif runjob.sh


runjob.sh
--------------------
./loadenv.sh
python3 job.py

Where loadenv.sh is ~160 line script that sets up paths/etc and launches a new shell with:

$NEW_SHELL "$@"

With the new shell being launched, bash commands stop being processed until the shell exits. Is there a way to pass the job to the new shell without editing loadenv.sh?


Solution

  • the "$@" accepts command line arguments entered after it as variables.

    editing runjob.sh to:

    ./loadenv.sh python3 job.py
    

    runs the job in the environment. I found this only works for 1 argument, with the shell exiting on completion. So to run multiple jobs in the same batch submission it needs to be structured as:

    apptainer run container.sif runjob.sh
    
    
    runjob.sh
    --------------------
    ./loadenv.sh python3 job1.py
    ./loadenv.sh python3 job2.py
    ./loadenv.sh python3 job3.py
    ...