repo: uritools action: blob revision: path_from: getsrv revision_from: refs/heads/master: path_to: revision_to:
blob of:
/ getsrv
refs/heads/master:/getsrv
#!/usr/bin/env bash ### this -a isn't even used! what is it still here for? if [ "$1" = "-h" -o "$1" = "--help" ];then printf "usage: getsrv [-a|--all|-h|--help][excluded-host1] [excluded-host2] [...]\n" >&2 printf "example getsrv xmpp-server tcp thebackupbox.net\n" >&2 exit 1 fi if [ "$1" = "-a" -o "$1" = "--all" ];then head="uniq" shift else head="head -n1" fi record="_$1._$2.$3" shift 3 if [ "_$*" != "_" ];then #what am I even using this for? it looks to be allowing me to match response with the extra... oh. this is to exclude already tried. filter='grep -vF "'"$(printf "%s\n" "$*" | tr ' ' '\n')"'"' else filter=cat fi if which host >/dev/null;then host -t SRV "$record" $dns_server | cut '-d ' -f5- #echo "after host" >&2 elif which dig >/dev/null;then dig +short -t SRV "$record" $dns_server #echo "after dig" >&2 else echo "getsrv: how am I supposed to get a srv record without dig or host? giving up." >&2 exit 1 fi | grep '^[0-9][0-9]* [0-9][0-9]*' \ | sort -rn \ | rev \ | cut -b2- \ | rev \ | awk '{print $1, $2, $4":"$3}' \ | eval "$filter" \ | awk '{if(NR==1){D=$1}if(D==$1)print $0}' \ | cut '-d ' -f2- \ | awk '{for(i=0;i<=$1;i++) {print $0} }' \ | cut '-d ' -f2- \ | shuf 2>/dev/null \ | head -n1 \ ## that last pipeline tries to get pretty close to printing a properly weighted response, but not perfect.