bash - sh variable not working if blank -
need eyes one...
dns_lookup() { ip_set if [ `ip_ping ${ip_address}` -eq 0 ] host="" dig +short -x ${ip_address} | sed 's/\.$//g' | while read host if [ -z "${host}" ] host="unknown" fi echo "${ip_address},${host}" done fi
}
i desired results if ip pingable , has dns name. not results if ip pingable not have dns name.
ip_set() { ip_address="${a}.${b}.${c}.${d}" } ip_ping() { timeout ${delay} ping -q -c 1 -i 1 -w 1 -w 4 $1 > /dev/null 2>&1 ; echo $? }
perhaps need. tell me if need revisions.
dns_lookup() { ip_set if [ `ip_ping ${ip_address}` -eq 0 ] host="" dig +short -x ${ip_address} | sed 's/\.$//g' | { hashosts=false while read host if [ -n "${host}" ] hashosts=true echo "${ip_address},${host}" fi done [ "${hashosts}" = false ] && echo "${ip_address},unknown" } fi }
i have suggested change of function ip_ping that_other_guy did it.
Comments
Post a Comment