Created
September 10, 2025 17:30
-
-
Save tunaitis/0989eecbb143046b7fc5d5ef31c1ea03 to your computer and use it in GitHub Desktop.
A simple Bash script that downloads a sitemap, extracts all <loc> URLs, and submits them to the IndexNow API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # config | |
| SITEMAP_URL="" | |
| INDEXNOW_KEY="" | |
| # check config | |
| if [[ -z "$SITEMAP_URL" || -z "$INDEXNOW_KEY" ]]; then | |
| echo "Error: SITEMAP_URL and INDEXNOW_KEY must be set." | |
| exit 1 | |
| fi | |
| # download sitemap --- | |
| echo "Downloading sitemap from $SITEMAP_URL..." | |
| curl -s "$SITEMAP_URL" -o sitemap.xml | |
| # extract URLs | |
| URLS=$(xmllint --xpath '//*[local-name()="url"]/*[local-name()="loc"]/text()' sitemap.xml 2>/dev/null || true) | |
| # cleanup | |
| rm -f sitemap.xml | |
| # submit to indexnow | |
| echo "Submitting URLs to IndexNow..." | |
| for url in $URLS; do | |
| RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" \ | |
| "https://api.indexnow.org/indexnow?url=${url}&key=${INDEXNOW_KEY}") | |
| echo "[$RESPONSE] $url" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment