From b3c5152019221631b0de992cb94dc349b5396a6f Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Wed, 7 Aug 2019 11:42:38 -0500 Subject: [PATCH 1/4] Add more paths and check_domain script --- scripts/bin/check_domain | 70 ++++++++++++++++++++++++++++++++++++++++ shell/bash/paths | 1 + 2 files changed, 71 insertions(+) create mode 100755 scripts/bin/check_domain diff --git a/scripts/bin/check_domain b/scripts/bin/check_domain new file mode 100755 index 0000000..7db5ecc --- /dev/null +++ b/scripts/bin/check_domain @@ -0,0 +1,70 @@ +#!/usr/bin/env bash + +# suggested usage: ./check_domain | tee /tmp/chkdmn && sort /tmp/chkdmn + +# constants +AVAIL_REGEX='^No match|^NOT FOUND|^Not fo|AVAILABLE|^No Data Fou|has not been regi|No entri' +TIMEOUT_REGEX='^Timeout' + +COLOR_RESET="\x1b[0m" +COLOR_GREEN="\x1b[32m" +COLOR_YELLOW="\x1b[33m" +COLOR_RED="\x1b[31m" + +DOMAINS=( \ + '.com' '.net' '.org' '.eu' '.in' '.it' '.sk' '.ac' '.ae' '.af' '.ag' '.al' \ + '.am' '.as' '.at' '.ax' '.be' '.bi' '.bo' '.by' '.bz' '.cc' '.cd' '.cf' '.cg' \ + '.ch' '.ci' '.cl' '.cm' '.cn' '.co' '.cr' '.cx' '.cz' '.dk' '.dm' '.do' '.ec' \ + '.ee' '.es' '.fi' '.fm' '.fo' '.ga' '.gd' '.gf' '.gg' '.gl' '.gp' '.gq' '.gr' \ + '.gs' '.gt' '.gy' '.hk' '.hm' '.hn' '.ht' '.id' '.im' '.in' '.io' '.ir' '.is' \ + '.je' '.ke' '.kg' '.kz' '.la' '.lc' '.li' '.lt' '.lu' '.lv' '.ly' '.me' '.mg' \ + '.mk' '.ml' '.mn' '.mq' '.ms' '.mu' '.mw' '.mx' '.na' '.ne' '.ng' '.nl' '.nu' \ + '.nz' '.pe' '.ph' '.pk' '.pl' '.pr' '.pt' '.pw' '.qa' '.ro' '.rs' '.ru' '.rw' \ + '.sb' '.sc' '.sd' '.se' '.sh' '.si' '.sl' '.sr' '.st' '.su' '.sx' '.sg' '.tk' \ + '.tl' '.to' '.tv' '.tw' '.ug' '.vc' '.ve' '.vg' '.vn' '.vu' '.ws' \ + ) + +# check dependencies +if command -v whois >/dev/null 2>&1; then + : +else + echo "You need to install whois before proceeding!" + exit 2 +fi + +# check arguments +if [ "$#" == "0" ]; then + echo "You need to supply at least one argument!" + exit 1 +fi + +# main function +check_domain() { + if [ "$#" == "0" ]; then + echo "No domain specified." + return + fi + + DOMAIN="$1" + TMP=$(mktemp "check_domain_whois_${DOMAIN}_XXX") + whois "$DOMAIN" > "$TMP" 2>&1 + if egrep -q "$AVAIL_REGEX" "$TMP"; then + echo -e "$COLOR_GREEN$DOMAIN / available$COLOR_RESET" + elif egrep -q "$TIMEOUT_REGEX" "$TMP"; then + echo -e "$COLOR_YELLOW$DOMAIN / timed out$COLOR_RESET" + else + echo -e "$COLOR_RED$DOMAIN / unavailable$COLOR_RESET" + fi +} + +# iterate all provided domain names combined with all TLDs and check them +# concurrently +elements=${#DOMAINS[@]} +while (( "$#" )); do + for (( i=0; i<$ELEMENTS; i++ )); do + D="$1${DOMAINS[${i}]}" + check_domain "${D}" & + done + shift +done +wait diff --git a/shell/bash/paths b/shell/bash/paths index 8ee1973..379babd 100644 --- a/shell/bash/paths +++ b/shell/bash/paths @@ -6,6 +6,7 @@ export GOPATH="$HOME/.go" export PATH=$PATH:"$GOPATH/bin" export PATH=$PATH:"$DOTFILES_PATH/scripts/bin" export PATH=$PATH:"$DOTFILES_PATH/scripts/env_bin" +export PATH=$PATH:"$HOME/.env_bin" export PATH=$PATH:"$HOME/.cargo/bin" export PATH=$PATH:"$HOME/.yarn/bin" From 7d8327fa0f377f50bab9d119e5aad673d82b7e13 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Wed, 7 Aug 2019 11:43:12 -0500 Subject: [PATCH 2/4] Improve script wording --- scripts/bin/check_domain | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/bin/check_domain b/scripts/bin/check_domain index 7db5ecc..15d9b9d 100755 --- a/scripts/bin/check_domain +++ b/scripts/bin/check_domain @@ -6,8 +6,7 @@ AVAIL_REGEX='^No match|^NOT FOUND|^Not fo|AVAILABLE|^No Data Fou|has not been regi|No entri' TIMEOUT_REGEX='^Timeout' -COLOR_RESET="\x1b[0m" -COLOR_GREEN="\x1b[32m" +COLOR_RESET="\x1b[0m" COLOR_GREEN="\x1b[32m" COLOR_YELLOW="\x1b[33m" COLOR_RED="\x1b[31m" @@ -49,7 +48,7 @@ check_domain() { TMP=$(mktemp "check_domain_whois_${DOMAIN}_XXX") whois "$DOMAIN" > "$TMP" 2>&1 if egrep -q "$AVAIL_REGEX" "$TMP"; then - echo -e "$COLOR_GREEN$DOMAIN / available$COLOR_RESET" + echo -e "$COLOR_GREEN$DOMAIN / probably available$COLOR_RESET" elif egrep -q "$TIMEOUT_REGEX" "$TMP"; then echo -e "$COLOR_YELLOW$DOMAIN / timed out$COLOR_RESET" else From 0384caa1e2a7d5e7ed115a0dd28a53f16b62c187 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Wed, 7 Aug 2019 12:06:28 -0500 Subject: [PATCH 3/4] Add notes --- scripts/bin/check_domain | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/scripts/bin/check_domain b/scripts/bin/check_domain index 15d9b9d..649b775 100755 --- a/scripts/bin/check_domain +++ b/scripts/bin/check_domain @@ -1,5 +1,15 @@ #!/usr/bin/env bash +# TODO: +# + trap exit signals to cleanup all temp files and cancel all jobs +# + run in batches to prevent spawning way too many processes +# + detect when piping into another application and suppress colors? +# + temp file control (or none for no disk space)? +# + command line options or env vars? +# + --tlds "com,net,org" +# + --max-concurrent-whois-jobs +# + --avail-regex and --timeout-regex + # suggested usage: ./check_domain | tee /tmp/chkdmn && sort /tmp/chkdmn # constants @@ -44,23 +54,27 @@ check_domain() { return fi - DOMAIN="$1" - TMP=$(mktemp "check_domain_whois_${DOMAIN}_XXX") - whois "$DOMAIN" > "$TMP" 2>&1 - if egrep -q "$AVAIL_REGEX" "$TMP"; then - echo -e "$COLOR_GREEN$DOMAIN / probably available$COLOR_RESET" - elif egrep -q "$TIMEOUT_REGEX" "$TMP"; then - echo -e "$COLOR_YELLOW$DOMAIN / timed out$COLOR_RESET" + local domain="$1" + # create a unique temporary file + TMP=$(mktemp "${domain}_XXX") + # dump whois output into temp file + whois "$domain" > "$TMP" 2>&1 + # check contents and output appropriately + if egrep -q "$AVAIL_REGEX" "$TMP" > /dev/null 2>&1; then + echo -e "$COLOR_GREEN$domain / probably available$COLOR_RESET" + elif egrep -q "$TIMEOUT_REGEX" "$TMP" > /dev/null 2>&1; then + echo -e "$COLOR_YELLOW$domain / timed out$COLOR_RESET" else - echo -e "$COLOR_RED$DOMAIN / unavailable$COLOR_RESET" + echo -e "$COLOR_RED$domain / unavailable$COLOR_RESET" fi + rm "$TMP" } # iterate all provided domain names combined with all TLDs and check them # concurrently elements=${#DOMAINS[@]} while (( "$#" )); do - for (( i=0; i<$ELEMENTS; i++ )); do + for (( i=0; i<$elements; i++ )); do D="$1${DOMAINS[${i}]}" check_domain "${D}" & done From e7da7715d9e8b6898109cfa4835365174af50737 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Wed, 7 Aug 2019 12:10:02 -0500 Subject: [PATCH 4/4] Fix warnings --- scripts/bin/check_domain | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/scripts/bin/check_domain b/scripts/bin/check_domain index 649b775..4a4300e 100755 --- a/scripts/bin/check_domain +++ b/scripts/bin/check_domain @@ -55,28 +55,32 @@ check_domain() { fi local domain="$1" + # create a unique temporary file - TMP=$(mktemp "${domain}_XXX") + local tmp=$(mktemp "${domain}_XXX") + # dump whois output into temp file - whois "$domain" > "$TMP" 2>&1 + whois "$domain" > "$tmp" 2>&1 + # check contents and output appropriately - if egrep -q "$AVAIL_REGEX" "$TMP" > /dev/null 2>&1; then + if egrep -q "$AVAIL_REGEX" "$tmp" > /dev/null 2>&1; then echo -e "$COLOR_GREEN$domain / probably available$COLOR_RESET" - elif egrep -q "$TIMEOUT_REGEX" "$TMP" > /dev/null 2>&1; then + elif egrep -q "$TIMEOUT_REGEX" "$tmp" > /dev/null 2>&1; then echo -e "$COLOR_YELLOW$domain / timed out$COLOR_RESET" else echo -e "$COLOR_RED$domain / unavailable$COLOR_RESET" fi - rm "$TMP" + + # cleanup + rm "$tmp" } # iterate all provided domain names combined with all TLDs and check them # concurrently elements=${#DOMAINS[@]} while (( "$#" )); do - for (( i=0; i<$elements; i++ )); do - D="$1${DOMAINS[${i}]}" - check_domain "${D}" & + for (( i=0;i<${elements};i++ )); do + check_domain "$1${DOMAINS[${i}]}" & done shift done