Bash – SLURM: Custom standard output name

bashclusterslurm

When running a SLURM job using sbatch, slurm produces a standard output file which looks like slurm-102432.out (slurm-jobid.out). I would like to customise this to (yyyymmddhhmmss-jobid-jobname.txt). How do I go about doing this?

Or more generally, how do I include computed variables in the sbatch argument -o?

I have tried the following in my script.sh

#SBATCH -p core
#SBATCH -n 6
#SBATCH -t 1:00:00
#SBATCH -J indexing
#SBATCH -o "/home/user/slurm/$(date +%Y%m%d%H%M%S)-$(SLURM_JOB_ID)-indexing.txt"

but that did not work. The location of the file was correct in the new directory but the filename was just literal line $(date +%Y%m%d%H%M%S)-$(SLURM_JOB_ID)-indexing.txt.

So, I am looking for a way to save the standard output file in a directory /home/user/slurm/ with a filename like so: 20160526093322-10453-indexing.txt

Best Answer

Here is my take away from previous answers

  • %j gives job id
  • %x gives job name
  • I don't know how to get the date in the desired format. Job ID kind of serves as unique identifier across runs and file modified date captures date for later analysis.

My SBATCH magic looks like this:

#SBATCH --output=R-%x.%j.out
#SBATCH --error=R-%x.%j.err

I prefer adding R- as a prefix, that way I can easily move or remove all R-*

Related Question