-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_directory.sh
78 lines (63 loc) · 2.57 KB
/
generate_directory.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
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
#!/bin/bash
echo "<div id=\"outline-container-orgff25f82\" class=\"outline-2\">"
echo "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
echo "<colgroup>"
echo "<col class=\"org-left\" />"
echo "<col class=\"org-left\" />"
echo "</colgroup>"
echo "<tbody>"
echo "<tr>"
echo "<td class=\"org-left\">Jupyter Link</td>"
echo "<td class=\"org-left\">Name</td>"
echo "</tr>"
echo "<tr>"
echo "<td class=\"org-left\"> </td>"
echo "<td class=\"org-left\"> </td>"
echo "</tr>"
getArray() {
array=() # Create array
while IFS= read -r line # Read a line
do
IP+=("$line") # Append line to the array
done < "$1"
}
getArray "ips_newline_port.txt"
getArray() {
array=() # Create array
while IFS= read -r line # Read a line
do
NAME+=("$line") # Append line to the array
done < "$1"
}
# These 3 lines referred to the specific file format we had for one of our workshop response forms, where the user's full name was the 3rd column
cat "registration_tiny.csv" | cut -d ',' -f3 > "temp.csv" # extract only the name field
tail -n +2 "temp.csv" > cleaned_registration.csv # drop the header row - must use temp file or it deletes everything
rm temp.csv # delete temp file
# "cleaned_registration.csv" is the list of names taken from the Google response form for the workshop or otherwise generated
# Each name should be on its own line, with no header (or uncomment and modify the 'tail -n +2' line above to remove a header)
# It's possible that you'll need to manually edit this file if first and last names are separated initially (I've seen it both in one col and split between two)
# In that case just paste them together
getArray "cleaned_registration.csv"
rm cleaned_registration.csv
NAMEindices=${!NAME[*]}
for i in $NAMEindices; do
tempNAME=`echo "${NAME[$i]}" | tr -d '"'`
tempIP=`echo "${IP[$i]}" | tr -d '"'`
echo "<tr>"
echo "<td class=\"org-left\"><a href=\"http://"$tempIP"\">http://"$tempIP"</a></td>"
echo "<td class=\"org-left\">"$tempNAME"</td>"
echo "</tr>"
done
lengthDIFFERENCE=`expr ${#IP[@]} - ${#NAME[@]}` # compute how many spare IPs there are (there should always be ~5 spare IPs in case an instance dies)
lengthDIFFERENCE=`expr $lengthDIFFERENCE - 1` # account for 0-indexing
for j in `seq 0 $lengthDIFFERENCE`; do
tempIP=`echo ${IP[${#NAME[@]} + j]}`
echo "<tr>"
echo "<td class=\"org-left\"><a href=\"http://"$tempIP"\">http://"$tempIP"</a></td>"
echo "<td class=\"org-left\"><b>"Unassigned"</b></td>"
echo "</tr>"
done
echo "</tr>"
echo "</tbody>"
echo "</table>"
echo "</div>"