This page is no longer maintained.

All information and guides related to AI-LAB have been moved to https://hpc.aau.dk/ai-lab/ . Please visit the new site for the most up-to-date resources on AI-LAB.

Skip to content

Run a bash script

In this guide, we will demonstrate how to submit a job to Slurm using a bash script.

What is a bash script?

A bash script is essentially a text file with a series of commands that you would normally type in the terminal. When executed, the script runs these commands in sequence. Bash scripts are used to automate repetitive tasks, manage system operations, and perform complex workflows.

Let's create a bash script to submit a simple job that runs a Singularity container. This job will run a Python script inside the container.

Step 1: Prepare the Singularity Container

Step 2: Create the Python Script

Create a simple Python script named hello.py:

print("Hello from within the Singularity container!")

Step 3: Create the Bash Script

Create a bash script named run_job.sh:

Explanation of SBATCH Options:

  • --job-name: Name of the job (Optional).
  • --output: File where standard output will be written, with %j replaced by the job ID (Required).
  • --error: File where standard error will be written, with %j replaced by the job ID (Optional).
  • --time: Maximum run time (hh:mm) (Optional).
  • --ntasks: Number of tasks (Optional).
  • --cpus-per-task: Number of CPUs per task (Optional).
  • --mem: Memory per node (Optional).

Step 4: Submit the Job

To submit the job, use the sbatch command:

sbatch run_job.sh

After the job gets submitted, you should be able to find a file called something like result_x.out with Hello from within the Singularity container! in it.