Skip to content

Instantly share code, notes, and snippets.

@scumdestroy
Created February 19, 2024 16:10
Show Gist options
  • Save scumdestroy/8ca080ccad5a1993aa1063b83df3a67e to your computer and use it in GitHub Desktop.
Save scumdestroy/8ca080ccad5a1993aa1063b83df3a67e to your computer and use it in GitHub Desktop.
Search'N'Squeal : Bash script that searches a list of dorks on Github and notifies if new search result has appeared
#!/bin/sh
# func to do the search w/ curl
# syntax `perform_search anti-fur_APIKEY gh_APIKEYAPIKEYAPIKEY`
perform_search() {
local search_term="$1"
local api_key="$2"
curl -s -H "Authorization: token $api_key" "https://api.github.com/search/repositories?q=$search_term" | jq '.items[].html_url'
}
# File containing search terms
search_terms_file="search_terms.txt"
# GitHub API key
github_api_key="YOUR_GITHUB_API_KEY_HERE"
# File to store previous search results for each term
previous_results_dir="previous_results"
mkdir -p "$previous_results_dir"
# Loop through each search term in the file
while IFS= read -r search_term; do
# File to store previous search results for this term
previous_results_file="$previous_results_dir/$search_term.txt"
# Check if the file exists, if not create it
touch "$previous_results_file"
# Perform the search and store the results
current_results=$(perform_search "$search_term" "$github_api_key")
# Read previous search results from file
previous_results=$(cat "$previous_results_file")
# Compare current and previous results
new_results=$(comm -13 <(echo "$previous_results") <(echo "$current_results"))
# If there are new results, notify the user
if [ -n "$new_results" ]; then
echo "New search results found for \"$search_term\":"
echo "$new_results"
# Update the previous results file with the current results
echo "$current_results" > "$previous_results_file"
else
echo "No new search results found for \"$search_term\"."
fi
# Respect GitHub API rate limits
sleep 1s
done < "$search_terms_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment