-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcondor_usage
executable file
·81 lines (75 loc) · 2.89 KB
/
condor_usage
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
#!/bin/bash
function usage {
echo "This script prints the current machines in use, and who is using them."
echo " USAGE: condor_usage [--machine MACHINE | --no-summary]"
}
# Default values.
MACHINE=""
SUMMARY="y"
while [[ $# -gt 0 ]] ;
do
case $1 in
--machine)
MACHINE="${2}"
shift
shift
;;
--no-summary)
SUMMARY="n"
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "Too many positional arguments passed!"
usage
exit 1
;;
esac
done
function get_output() {
# The order of these clauses matches the order in condor's output,
# but not all jobs have all these fields! Hence the variable resets on every job id.
condor_q -all -l | awk '/^ClusterId = /{jobid = $3; \
wholemachine = 0; \
report_job = 0; \
}\
/^IsWholeMachineJob = /{wholemachine = ($3 == "true");}\
/^JobStatus = /{report_job = ($3 == "2");}\
/^RemoteHost = /{if (report_job) { \
slot = $3; \
if (index(slot, "'"$MACHINE"'") == 0) { \
report_job = 0; \
} \
}}\
/^User = /{if (report_job) { \
printf "\033[1;37m%s\033[90m \tin use by \033[1;33m%s\033[90m\tjob: \033[1;0m%s\033[90m\t",slot,$3,jobid; \
if (wholemachine) { \
printf "\033[1;30mWHOLE MACHINE!\033[0m\n"; \
} else { \
printf "\033[0m\n"; \
} \
}}'
}
if [ ${SUMMARY} == "n" ]; then
get_output
else
get_output | \
awk 'BEGIN {OFS=", "} \
{ split($1, arr, "@"); \
resource = substr(arr[2], 0, length(arr[2]) - 6); \
split($5, arr, "@"); \
user = substr(arr[1], 9, length(arr[1])); \
if ($8 ~ /WHOLE/) { \
user = user " (whole machine)"; \
} \
key = resource "@" user; \
if (!(key in unique)) { \
users[resource] = (users[resource] ? users[resource] OFS : "") user; \
unique[key]++; \
} \
} \
END { for (r in users) printf "\033[1;37m%35s\033[0m \033[1;90min use by \033[1;33m%s\033[0m\n",r,users[r]; }'
fi