-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlauncher.sh
59 lines (50 loc) · 1.31 KB
/
launcher.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
#!/bin/bash
# Ping a list of hosts and save the ones that are up to a file
# Usage: ping.sh <file with list of hosts> <desire port> <numer of hosts> <NIP>
LABS=$1
PORT=$2
MAX_HOSTS=$3
NIP=$4
# Check if the file exists
if [ ! -f ${LABS} ]; then
echo "File ${LABS} does not exist"
exit 1
else
rm "endpoints.txt"
fi
# Check if the file is empty
if [ ! -s ${LABS} ]; then
echo "File ${LABS} is empty"
exit 1
fi
# Check if the file is readable
if [ ! -r ${LABS} ]; then
echo "File ${LABS} is not readable"
exit 1
fi
# Loop through the list of hosts until reach the max number of hosts
num_hosts=0
while read _ host; do
echo "Pinging $host... "
# Check max number of hosts
if [ $((${MAX_HOSTS} == $num_hosts)) -eq 1 ]; then
echo "Max number of hosts reached."
break
fi
ping -c 1 $host > /dev/null 2>&1
# check if the host is up
if [ $? -eq 0 ]; then
echo "$host is up"
num_hosts=$((num_hosts+1))
echo ${host}:$((${PORT}+num_hosts)) >> "endpoints.txt"
else
echo "$host is down"
fi
done < ${LABS}
# run all workers
IFS=:
while read ip port; do
echo $ip $port
# execute remote command
ssh -i "~/.ssh/id_rsa" a${NIP}@${ip} "~/Desktop/sisdis-pr-1/bin/./worker ${ip} ${port}" > /dev/null 2>&1 &
done < "endpoints.txt"