-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRestart.sh
executable file
·29 lines (24 loc) · 1.12 KB
/
Restart.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
set -eu
# Usage:
# ./Restart.sh <ProjectNumberOrName> <SLURM_JOB_NAME> <SLURM_JOB_ID> <YOUR_EMAIL> <MACHINE_NAME>
#
# Get command line arguments
ProjectNumberOrName=$1
JobName=$2
JobID=$3
EMAIL=$4
Machine=$5
# Get node number as well
ThisMachine=$Machine"_"$(hostname -s)
# From https://stackoverflow.com/questions/60082303/how-to-configure-slurm-to-email-out-file
secs_to_human(){
echo "$(( ${1} / 3600 )):$(( (${1} / 60) % 60 )):$(( ${1} % 60 ))"
}
start=$(date +%s)
echo "$(date -d @${start} "+%Y-%m-%d %H:%M:%S"): ${JobName} start id=${JobID}\n"
LOGFILE=".bfi_restart/"$ProjectNumberOrName".log"
# Run RestartProject and send email with summary
( RestartProject -r $ProjectNumberOrName) \
&& (tail -n 6 $LOGFILE | mail -s "RestartProject -r $ProjectNumberOrName ended after $(secs_to_human $(($(date +%s) - ${start}))), on machine=$ThisMachine id=$JobID" $EMAIL && echo Mail sent to $EMAIL) \
|| (tail -n 6 $LOGFILE | mail -s "RestartProject -r $ProjectNumberOrName Failed after $(secs_to_human $(($(date +%s) - ${start}))), on machine=$ThisMachine id=$JobID" $EMAIL && echo Mail sent to $EMAIL && exit $?)