Last active
December 9, 2022 17:47
-
-
Save jdennes/49d2fd3b77668a4c078df3127700da97 to your computer and use it in GitHub Desktop.
Shell script to get Site Admin reports on GitHub Enterprise
This file contains 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
#!/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