-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimpleapi
More file actions
executable file
·91 lines (87 loc) · 3.17 KB
/
simpleapi
File metadata and controls
executable file
·91 lines (87 loc) · 3.17 KB
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
84
85
86
87
88
89
#!/bin/bash
outstart="<simpleapi>"
outend="</simpleapi>"
currentuser=$(whoami)
projpattern="^([abgps][0-9]|staff)"
case "$1" in
clusterinfo)
echo $outstart
echo "<clusterinfo>"
echo "<maxnodes>348</maxnodes>"
echo "<maxcpus>8</maxcpus>"
echo "<partitions>"
for partition in "core" "node" "devel"; do
echo "<partition>$partition</partition>"
done;
echo "</partitions>"
echo "</clusterinfo>"
echo $outend
;;
projinfo)
echo $outstart;
echo "<projinfo>";
projinfo_tmpfile="/tmp/projinfo_$(date +%Y%m%d%H)"
#if [[ ! -f $projinfo_tmpfile ]]; then
projinfo `groups|tr " " "\n"|egrep "$projpattern"|tr "\n" " "` > $projinfo_tmpfile;
#fi;
firstgroupinfo=true;
for line in $(cat $projinfo_tmpfile|tr " " "_"); do
groupinfo_start=$(echo $line|grep -P "\-{10,100}")
if $firstgroupinfo && [[ -n $groupinfo_start ]]; then
echo "<groupinfo>";
firstgroupinfo=false;
elif [[ !$firstgroupinfo && -n $groupinfo_start ]]; then
echo "</groupinfo>";
echo "<groupinfo>";
fi;
# Output the info for the group as a whole
echo $line|grep -P "^[a-z]"|sed -r 's|([a-z0-9]+)\_+([0-9]+\.[0-9]+)\_+([0-9a-z][0-9a-z_]+)|<name>\1</name><time>\2</time><allocation>\3</allocation>|g'
# Output info for each user in the group
echo $line|grep -P "^\_+[a-z]"|sed -r 's|\_+([a-z]+)\_+([0-9]+\.[0-9]+)(\_+([0-9]+))?|<user><name>\1</name><time>\2</time><allocation>\4</allocation></user>|g'
done;
echo "</groupinfo>"
echo "</projinfo>"
echo $outend
;;
jobinfo)
echo $outstart
echo "<jobinfo>"
echo "<jobs>"
squeue --noheader --user=$currentuser --format="<job id=\"%i\" partition=\"%P\" name=\"%j\" username=\"%u\" state=\"%T\" time_elapsed=\"%M\" nodescnt=\"%D\" nodelist=\"%R\" />"
echo "</jobs>"
echo "</jobinfo>"
echo $outend
;;
userinfo)
echo $outstart
echo "<userinfo>"
echo "<username>$currentuser</username>"
echo "<projects>"
for proj in $(groups|tr " " "\n"|grep -P "$projpattern"); do
echo "<project>$proj</project>"
done;
echo "</projects>"
echo "</userinfo>"
echo $outend
;;
modulesforbin)
if [[ -n $2 ]]; then
# Set file to use as cache for modules info
MODCACHE=~/.modulescache
binary=$2
module load bioinfo-tools
echo $outstart
echo "<modulesforbin>"
echo "<modules>"
module -i apropos $binary 2>&1|grep -P "^[a-zA-Z0-9\.]+/[0-9]"|grep -v "ERROR"|awk '{ print "<module name=\"" $1 "\" />" }';
echo "</modules>"
echo "</modulesforbin>"
echo $outend;
else
echo "You have to specify a binary after 'modulesforbin'!" 2>&1; exit 1;
fi;
;;
*)
echo "Usage: $0 {clusterinfo|projinfo|jobinfo|userinfo|modulesforbin <binary>}"
exit 1
esac