Skip to content

Instantly share code, notes, and snippets.

@xinau
Created February 5, 2021 09:07
Show Gist options
  • Save xinau/dfc17d1cd880403a2ed141fad9d107c9 to your computer and use it in GitHub Desktop.
Save xinau/dfc17d1cd880403a2ed141fad9d107c9 to your computer and use it in GitHub Desktop.
script for getting available domains based on the filesysetm layout
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# sudo ./domains.sh | tee domains.txt | awk '/AVAILABILITY_AVAILABLE$/ {print $1}'
structs=$(find / -maxdepth 2 -mindepth 2 \
| grep -E "^/(media|run|dev)" \
| grep -v -E "(_|\.)" \
| awk -F '/' '{print "{\"domainName\": [{\"sld\": \""$3"\", \"tld\": \""$2"\"}]}" }')
for data in $structs; do
domain=$(echo $data | jq -r '.domainName[0] | "\(.sld).\(.tld)"')
availability=$(curl 'https://domains.google.com/v1/Main/FeSearchService/Availability' -sS \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data-raw "$data" \
| tail -n 1 \
| jq -r '.availabilityResponse.results.result[0].supportedResultInfo.availabilityInfo.availability')
echo "$domain - $availability"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment