#!/bin/bash TARGET=/etc/OliveTin/entities/servers.yaml TARGET_TEMP=${TARGET}.tmp test -e ${TARGET_TEMP} && rm -f ${TARGET_TEMP} while read -r line do clean_line=${line%%#*} ip=${clean_line%%[[:space:]]*} name=${clean_line##*[[:space:]]} status=offline if [ "$ip" != "" -a "$name" != "" -a "$ip" != "127.0.0.1" -a "$ip" != "::1" ] then (ping -c 1 -w 1 $ip 2> /dev/null > /dev/null if [ $? -eq 0 ] then status=online fi echo " - name: $name ip: $ip status: $status" >> ${TARGET_TEMP}) fi done < "/etc/hosts" wait test -e ${TARGET_TEMP} && mv ${TARGET_TEMP} ${TARGET}