Introduction
Now we’ll see how to run a Bash script on the cluster. Before proceeding, make sure you’ve read the How To Run tutorial first.
Simple BASH example
Let’s start with the following script. We initiate a one minute sleep to allow it to run. This is such a simple example, we could have included it directly in the slurm script. In practice though, we’ll usually want to keep our functional code separate from our scripts.
Download: ..code-2018/taki/BASH/pause.bash
Here is the slurm script we will use to launch it.
Download: ..code-2018/taki/BASH/run.slurm
We first make our bash script executable, before submitting the job.
[reetam1@taki-usr1 bashtest]$ ls -l total 5 -rw-rw---- 1 reetam1 pi_gobbert 80 Apr 28 2011 pause.bash -rw-rw---- 1 reetam1 pi_gobbert 223 Feb 3 09:24 run.slurm [reetam1@taki-usr1 bashtest]$ chmod 760 pause.bash [reetam1@taki-usr1 bashtest]$ ls -l total 5 -rwxrw---- 1 reetam1 pi_gobbert 80 Apr 28 2011 pause.bash* -rw-rw---- 1 reetam1 pi_gobbert 223 Feb 3 09:24 run.slurm [reetam1@taki-usr1 bashtest]$ sbatch run.slurm Submitted batch job 3544107
After about a minute, we get the following output.
[reetam1@taki-usr1 bashtest]$ ls -l total 6 -rwxrw---- 1 reetam1 pi_gobbert 80 Apr 28 2011 pause.bash* -rw-rw---- 1 reetam1 pi_gobbert 223 Feb 3 09:24 run.slurm -rw-rw---- 1 reetam1 pi_gobbert 0 Feb 3 09:31 slurm.err -rw-rw---- 1 reetam1 pi_gobbert 90 Feb 3 09:32 slurm.out [reetam1@taki-usr1 bashtest]$ more slurm.out Script started at Wed Feb 3 09:31:31 EST 2021 Script ended at Wed Feb 3 09:32:34 EST 2021 [reetam1@taki-usr1 bashtest]$
If we had killed the job during its execution, the scheduler would have been able to stop it cleanly, and no processes would continue to run on the compute node.