Skip to content

Instantly share code, notes, and snippets.

@Integralist
Last active January 21, 2025 15:26
Show Gist options
  • Save Integralist/1391150b69eebcaac98984627ba26b7d to your computer and use it in GitHub Desktop.
Save Integralist/1391150b69eebcaac98984627ba26b7d to your computer and use it in GitHub Desktop.
[xarg parallel processing] #xarg
# update --cursor value to acquire all the relevant domain data (see batch-identify-domains.sh)
fastly domain-v1 list --fqdn=test-tf --cursor=<REDACTED> --limit=100 --json | jq -r .data[].id >> /tmp/delete-domains
# now delete all those items
cat /tmp/delete-domains | xargs -P "$(sysctl -n hw.ncpu)" -I % fastly domain-v1 delete --domain-id=%
#!/bin/bash
# Initial cursor value
cursor="<STARTING CURSOR>"
output_file="/tmp/delete-domains"
# Clear the output file before appending data
> "$output_file"
while true; do
# Run the command and capture the output
response=$(go run ./cmd/fastly/main.go domain-v1 list --fqdn=tf-test --limit=100 --json --cursor="$cursor")
# Extract IDs and append to the output file
echo "$response" | jq -r .data[].id >> "$output_file"
# Extract the next cursor value from the JSON response
next_cursor=$(echo "$response" | jq -r .meta.next_cursor)
# Check if there is no next cursor (end of pagination)
if [[ -z "$next_cursor" || "$next_cursor" == "null" ]]; then
echo "No more data to fetch. Exiting loop."
break
fi
# Update the cursor for the next iteration
cursor="$next_cursor"
echo "Fetched batch. Next cursor: $cursor"
done
echo "All data fetched and saved to $output_file."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment