Created
August 9, 2022 14:24
-
-
Save ultranity/d672ba80b79a4d9b0e2c807c2a106260 to your computer and use it in GitHub Desktop.
Slurm-sbatch-email-with-output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#SBATCH -J MyModel | |
#SBATCH -n 1 # Number of cores | |
#SBATCH -t 1-00:00 # Runtime in D-HH:MM | |
#SBATCH -o JOB%j.out # File to which STDOUT will be written | |
#SBATCH -e JOB%j.out # File to which STDERR will be written | |
#SBATCH --mail-type=BEGIN | |
#SBATCH [email protected] | |
secs_to_human(){ | |
echo "$(( ${1} / 3600 )):$(( (${1} / 60) % 60 )):$(( ${1} % 60 ))" | |
} | |
start=$(date +%s) | |
echo "$(date -d @${start} "+%Y-%m-%d %H:%M:%S"): ${SLURM_JOB_NAME} start id=${SLURM_JOB_ID}\n" | |
### exec task here | |
( << replace with your task here >> ) \ | |
&& (cat JOB$SLURM_JOB_ID.out |mail -s "$SLURM_JOB_NAME Ended after $(secs_to_human $(($(date +%s) - ${start}))) id=$SLURM_JOB_ID" [email protected] && echo mail sended) \ | |
|| (cat JOB$SLURM_JOB_ID.out |mail -s "$SLURM_JOB_NAME Failed after $(secs_to_human $(($(date +%s) - ${start}))) id=$SLURM_JOB_ID" [email protected] && echo mail sended && exit $?) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in this snippet, only default stderr&stdout log will be attached as content by
cat JOB$SLURM_JOB_ID.out
and pipe to mailxfor more logs/plots, you need to check how the mail client in your env supports adding attachments. as ref:https://stackoverflow.com/questions/902591/how-to-attach-a-file-using-mail-command-on-linux