Skip to content

Instantly share code, notes, and snippets.

@rashamalek
Forked from jdennes/get-site-admin-report.sh
Created February 27, 2019 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rashamalek/1ee11b8cdd7d0e2c89797e084c8c26f4 to your computer and use it in GitHub Desktop.
Save rashamalek/1ee11b8cdd7d0e2c89797e084c8c26f4 to your computer and use it in GitHub Desktop.
Shell script to get Site Admin reports on GitHub Enterprise
#!/bin/bash
# Export USERNAME, PASSWORD, and REPORT_URL
# REPORT_URL should look something like https://my.ghe/stafftools/reports/all_users.csv
# See: https://help.github.com/enterprise/admin/articles/site-admin-dashboard/#reports
set -e
for i in $(seq 1 5); do
echo "Trying to get report..."
result=$(curl -s -L -u $USERNAME:$PASSWORD $REPORT_URL)
# If the result contains the report content (200 OK), output to file.
# Otherwise, it's probably still being generated (202 Accepted), so wait a bit
# and try again.
if echo $result | grep -q 'created_at,id,login'; then
echo "$result" > report.csv
echo "Saved report to report.csv"
exit 0
else
echo "Report is still being generated..."
sleep 10
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment