-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwait.sh
More file actions
executable file
·34 lines (28 loc) · 829 Bytes
/
wait.sh
File metadata and controls
executable file
·34 lines (28 loc) · 829 Bytes
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
#!/bin/bash
# Check if at least one VM IP address is provided as an argument
if [ $# -eq 0 ]; then
echo "Usage: $0 <VM_IP1> <VM_IP2> <VM_IP3>"
exit 1
fi
# Function to check if SSH server is available
check_ssh() {
nc -z -w 1 "$1" 22
}
# Create an array of VM IP addresses from command-line arguments
vms=("$@")
# Loop until all SSH servers are unreachable or the list is empty
while [ ${#vms[@]} -gt 0 ]; do
for ((i = 0; i < ${#vms[@]}; i++)); do
vm_ip="${vms[i]}"
if check_ssh "$vm_ip"; then
echo "SSH server on $vm_ip is running."
unset 'vms[i]' # Remove the VM from the list
vms=("${vms[@]}") # Re-index the array
fi
done
if [ ${#vms[@]} -eq 0 ]; then
echo "All SSH servers are running."
break
fi
sleep 5
done