-
Notifications
You must be signed in to change notification settings - Fork 12
/
jobState
executable file
·84 lines (60 loc) · 1.61 KB
/
jobState
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# Gets state of slurm job given its id as an argument
job=$1
running=( CONFIGURING PENDING RUNNING RESIZING SUSPENDED PREEMPTED COMPLETING )
failed=( BOOT_FAIL CANCELLED DEADLINE FAILED NODE_FAIL TIMEOUT OUT_OF_MEMORY )
completed=COMPLETED
failedLabel=failed
runningLabel=running
completedLabel=success
dateS=$(date -d "-10 days" +'%Y-%m-%d')
# Gets state of job
let timeMultiplier=4
let sleepTime=1
while true
do
sacctOut=`sacct -n -j $1 --format "JobID,State" -P -S $dateS`
if [ "$?" == "0" ]
then
break
fi
sleep $sleepTime
let sleepTime=$sleepTime*$timeMultiplier
if [ "$sleepTime" -gt "120" ]
then
sleepTime=120
fi
done
state=`echo "$sacctOut" | grep -v .extern | cut -f2 -d "|"` # Ignores extern process from SLURM
#Checking if completed
nlinesCompleted="$(echo "$state" | perl -ne "if (\$_ =~ /$completed/) {print}" | wc -l)"
nlines="$(echo "$state" | wc -l)"
if [ "$nlinesCompleted" == "$nlines" ]
then
echo "$completedLabel"
exit 0
fi
# Checking if running
for i in ${running[@]}
do
# If running in anyway the number of lines will not be 0
nlines="$(echo "$state" | perl -ne "if (\$_ =~ /$i/) {print}" | wc -l)"
if [ "$nlines" != "0" ]
then
echo "$runningLabel"
exit 0
fi
done
# Checking if failed
for i in ${failed[@]}
do
# If failed in anyway the number of lines will not be 0
nlines="$(echo "$state" | perl -ne "if (\$_ =~ /$i/) {print}" | wc -l)"
if [ "$nlines" != "0" ]
then
echo "$failedLabel"
exit 0
fi
done
echo "$runningLabel"
exit 0