Przejdź do treści

BASH – Script ping few machines at the same time

#!/bin/bash

# Set array of servers
servers=("server1" "server2" "server3")

# Set timeout
timeout=5

# Function to check ping for a server
check_ping() {
    host=$1
    ping -c 1 -W $timeout $host > /dev/null
    if [ $? -eq 0 ]; then
        echo "$host is responding to ping."
    else
        echo "$host is not responding to ping."
    fi
}

# Iterate over the servers array and check ping
for server in "${servers[@]}"; do
    check_ping "$server"
done

Dodaj komentarz

Twój adres email nie zostanie opublikowany. Wymagane pola są oznaczone *