From 46c16857c5d90b6717a4d3ee937fb982f7b5cf96 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Thu, 3 Mar 2022 11:04:49 +0100 Subject: [PATCH] no param: 2 searches in name and alias --- dns-search.sh | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/dns-search.sh b/dns-search.sh index 21a8869..5e3a17f 100755 --- a/dns-search.sh +++ b/dns-search.sh @@ -7,23 +7,25 @@ # 2021-10-29 v1.0 <axel.hahn@iml.unibe.ch> # 2022-01-14 v1.0 <axel.hahn@iml.unibe.ch> 1st public version # 2022-03-01 v1.1 <axel.hahn@iml.unibe.ch> fix usage with 1st param "name" +# 2022-03-03 v1.2 <axel.hahn@iml.unibe.ch> no param: 2 searches in name and alias # ====================================================================== +# ---------------------------------------------------------------------- +# HELP +# ---------------------------------------------------------------------- if [ -z "$1" ] || [ "$1" = "-h" ]; then cat <<EOH Search for hostnames or aliases in Infoblox API It uses dns-api.sh and adds the return field for aliases. -SYNTAX: dns-search.sh name|alias REGEX +SYNTAX: dns-search.sh [name|alias] REGEX EXAMPLES: (1) search for a hostname / A record - dns-search.sh www.iml.unibe.ch - OR dns-search.sh name www.iml.unibe.ch (2) @@ -32,14 +34,22 @@ search for CNAME - use "alias" as 1st parameter (3) The search supports regex: - dns-search.sh ^assets - dns-search.sh "^(connector|examinator).*measured.stage" + dns-search.sh name ^assets + dns-search.sh name "^(connector|examinator).*measured.stage" + +(4) +Lazy mode: do not add name or alias to start 2 requests to search in name and +alias fields + dns-search.sh ufive EOH exit 0 fi -mytype=name +# ---------------------------------------------------------------------- +# MAIN +# ---------------------------------------------------------------------- +mytype= if echo "$1" | grep -E '^(name|alias)$' >/dev/null then mytype=$1 @@ -52,8 +62,14 @@ mysearch=$1 # ---------------------------------------------------------------------- echo "; === DNS SEARCH" -echo "; search for type=$mytype" -echo "; search regex=$mysearch" +echo "; search for type : $mytype" +echo "; search regex : $mysearch" echo ";" +if [ -n "$mytype" ]; then + "$( dirname $0 )"/dns-api.sh GET "/record:host?${mytype}~=${mysearch}&_return_fields%2B=aliases" +else + "$( dirname $0 )"/dns-api.sh GET "/record:host?name~=${mysearch}&_return_fields%2B=aliases" + "$( dirname $0 )"/dns-api.sh GET "/record:host?alias~=${mysearch}&_return_fields%2B=aliases" +fi -"$( dirname $0 )"/dns-api.sh GET "/record:host?${mytype}~=${mysearch}&_return_fields%2B=aliases" +# ---------------------------------------------------------------------- \ No newline at end of file -- GitLab