Let’s write a wrapper script for the sbatch command. This wrapper will check the current partition and decide whether to allow the job submission or display the error message “hey, you can’t run this.” Here’s a sample bash wrapper script:

#!/bin/bash

# Define the allowed partition name
allowed_partition="dev"

# Get the current partition from the environment variable
current_partition=$(scontrol show job $SLURM_JOBID | grep "Partition=" | cut -d= -f2)

# Check if the current partition is allowed
if [ "$current_partition" == "$allowed_partition" ]; then
    # If the current partition is allowed, pass the job submission to sbatch
    sbatch "$@"
else
    # If the current partition is not allowed, display the error message
    echo "Hey, you can't run this. Submit this job to the $allowed_partition partition."
fi

Save the above script in a file, for example, my_sbatch_wrapper.sh, and make it executable using the following command:

chmod +x my_sbatch_wrapper.sh

Now, when users want to submit jobs, they can use my_sbatch_wrapper.sh instead of directly using sbatch. The wrapper will check if the current partition is the allowed partition (in this case, “dev”). If it is, the job will be submitted with sbatch. Otherwise, the error message will be displayed.

For example:

./my_sbatch_wrapper.sh my_job_script.sh

Replace my_job_script.sh with the actual script you want to submit as a job. The wrapper script will handle the partition validation before submitting the job to SLURM.