Skip to content
Snippets Groups Projects
Commit 46c16857 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

no param: 2 searches in name and alias

parent f8e1e63e
Branches
No related tags found
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment