Sample SLURM Job Scripts
This page provides a collection of sample SLURM job scripts designed for various purposes. These scripts are intended for demonstration purposes and can be used to understand the structure of SLURM job submissions and how to interact with the cluster.
Printing Loaded Modules
This script lists all currently loaded modules on the cluster, which can help you understand which software packages are available for use.
Script: list_modules.sh
#!/bin/bash
#SBATCH --job-name=list_modules # Job name
#SBATCH --output=list_modules.out # Standard output file
#SBATCH --error=list_modules.err # Standard error file
# List currently loaded modules
module list
How to Use:
- Save this script as
list_modules.sh. - Submit the script using
sbatch list_modules.sh. - Check the output in the
list_modules.outfile.
Checking Available Disk Space
This script prints the available disk space on the system, which can be useful to monitor the storage usage on your home or project directories.
Script: check_disk_space.sh
#!/bin/bash
#SBATCH --job-name=check_disk_space # Job name
#SBATCH --output=check_disk_space.out # Standard output file
#SBATCH --error=check_disk_space.err # Standard error file
# Check available disk space
df -h
How to Use:
- Save this script as
check_disk_space.sh. - Submit the script using
sbatch check_disk_space.sh. - The available disk space information will be output to
check_disk_space.out.
Sample Script 3: Printing the Date and Time
This script prints the current date and time, which can help you verify when your job was started and track the duration of the job.
Script: print_date.sh
#!/bin/bash
#SBATCH --job-name=print_date # Job name
#SBATCH --output=print_date.out # Standard output file
#SBATCH --error=print_date.err # Standard error file
# Print the current date and time
date
How to Use:
- Save this script as
print_date.sh. - Submit the script using
sbatch print_date.sh. - The current date and time will be printed in the
print_date.outfile.
Running a Simple R Script
This script runs a simple R script that prints "Hello, World!", which demonstrates how to submit and run an R job using SLURM.
Script: run_r_demo.sh
#!/bin/bash
#SBATCH --job-name=r_demo # Job name
#SBATCH --output=r_demo.out # Standard output file
#SBATCH --error=r_demo.err # Standard error file
#SBATCH --mem=1gb # Memory request
# Load R module
module load R/4.5.0
# Run a simple R script that prints "Hello, World!"
echo "cat('Hello, World!\n')" | Rscript --vanilla -
How to Use:
- Save this script as
run_r_demo.sh. - Submit the script using
sbatch run_r_demo.sh. - The output will be shown in
r_demo.out, where it should print "Hello, World!".
Running a Simple Shell Command (Echo)
This script demonstrates how to use a simple echo command to print a message, which is useful for testing job submission with minimal complexity.
Script: echo_message.sh
#!/bin/bash
#SBATCH --job-name=echo_message # Job name
#SBATCH --output=echo_message.out # Standard output file
#SBATCH --error=echo_message.err # Standard error file
# Print a custom message to the output file
echo "This is a demo job running on the cluster!"
How to Use:
- Save this script as
echo_message.sh. - Submit the script using
sbatch echo_message.sh. - The message "This is a demo job running on the cluster!" will appear in the
echo_message.outfile.