Skip to content

Instantly share code, notes, and snippets.

@phgeraldeli
Created June 22, 2021 19:17
Show Gist options
  • Save phgeraldeli/e27ce4fe0249a17edc893131acb3e732 to your computer and use it in GitHub Desktop.
Save phgeraldeli/e27ce4fe0249a17edc893131acb3e732 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Get all group owners from gitlab
MY_ACCESS_TOKEN=$1
curl -s --location --request GET 'http://gitlab.intranet/api/v4/groups' --header "PRIVATE-TOKEN: ${MY_ACCESS_TOKEN}" -o file.txt
grep -Po '"id":\d+' file.txt | cut -d: -f2 > ids.txt
grep -Po 'web_url":[^,]+' file.txt > names.txt
for X in $(cat ids.txt); do
curl -s --location --request GET "http://gitlab.intranet/api/v4/groups/${X}/members/" --header "PRIVATE-TOKEN: ${MY_ACCESS_TOKEN}" > members.json
echo ${X} - $(head -1 names.txt)
sed -i 1d names.txt
sed -i 's/]\[/,/g' members.json
python -m json.tool members.json | grep -A6 -P '(access_level": 50)' | grep -P '("name|access_level)'
done > owner_members.txt
rm -f members.json ids.txt file.txt names.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment