1. #!bin/bash
    2. # 所以主机,以空格分隔
    3. ALL_HOSTS=(IP 地址 IP 地址)
    4. for host in ${ALL_HOSTS[*]}
    5. do
    6. {
    7. start_time=$(date +'%s')
    8. ssh $host "hostname" &>/dev/null
    9. sleep 2
    10. stop_time=$(date +'%s')
    11. time_consuming=$((stop_time-start_time))
    12. echo "$host: $time_consuming" >>hostname.txt
    13. }&
    14. done
    15. wait
    16. host=$(sort -n -k 2 hostname.txt | head -1 | awk -F':' '{print $1}')
    17. ssh $host "top -b -n 1"