-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserjobhist
41 lines (35 loc) · 1.31 KB
/
userjobhist
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
#!/bin/bash
if test $# -ne 2
then
echo "Display user job history"
echo "Default to display job history for last 7 days for current user"
echo "Usage: userjobhist days user"
fi
set -e -o pipefail
if [[ -z $1 ]]; then
days=7
else
days=$1
if [[ $1 =~ [[:alpha:]] || $1 -lt 1 ]]; then
printf "%s\n" "Error: The first argument should be a positive integer indicating days to list in history"
exit 1
fi
fi
if [[ -z $2 ]]; then
user=$USER
else
user=$2
# Check if user exists
if [[ "$(id $user 2>&1)" = *"no such user"* ]]; then
printf "%s\n" "No such user: $user"
exit 1
fi
fi
# Set sacct format
format=user%9,start%10,jobid%13,jobname%12,partition,state,elapsed%11,nnodes%5,ncpus%4,reqmem%8,reqtres%-50
printf "%s\n" "----------------------------------------------------------------------------------------------------------"
printf "%s\n" " User Startdate Job ID Job Name Partition State Elapsed Nodes CPUs Memory GPUs"
printf "%s\n" "--------- ---------- ------------- ------------ ---------- ---------- ----------- ----- ---- -------- ----"
sacct -n -X -o $format -u $user -S $(date --date="-$days day" +%Y-%m-%d) |
# Extract number of GPUs requested
sed -r 's/billing=.*gres\/gpu=([^,]*),.*/\1/; s/billing=.*/0/'