-
Notifications
You must be signed in to change notification settings - Fork 2
/
DevTunnelMultipleSession.sh
64 lines (56 loc) · 1.18 KB
/
DevTunnelMultipleSession.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
#!/bin/bash
red=$'\e[1;31m'
grn=$'\e[1;32m'
end=$'\e[0m'
domain=$1
os=$2
input="DeviceList.txt"
readLineIndex=0
while IFS= read -r line || [ -n "$line" ]
do
deviceIdArray[readLineIndex]=$line
readLineIndex=$((readLineIndex+1))
done < "$input"
prep_term()
{
unset term_kill_needed
trap 'handle_term' TERM INT
}
handle_term()
{
if [ "${term_child_pid[0]}" ]; then
for ((i=0; i<readLineIndex; i++))
do
kill -TERM "${term_child_pid[$i]}" 2>/dev/null
done
else
term_kill_needed="yes"
fi
}
wait_term()
{
if [ "${term_kill_needed}" ]; then
for ((i=0; i<readLineIndex; i++))
do
kill -TERM "${term_child_pid[$i]}" 2>/dev/null
done
fi
for ((i=0; i<readLineIndex; i++))
do
wait "${term_child_pid[$i]}" 2>/dev/null
done
trap - TERM INT
for ((i=0; i<readLineIndex; i++))
do
wait "${term_child_pid[$i]}" 2>/dev/null
done
}
prep_term
for ((i=0; i<readLineIndex; i++))
do
echo "${deviceIdArray[$i]}"
/bin/bash DevTunnelCLISession.sh "$domain" "${deviceIdArray[$i]}" "$os" &
term_child_pid[$i]=$!
sleep 15
done
wait_term "$term_child_pid1" "$term_child_pid2"