Created
September 1, 2022 22:00
-
-
Save dennisseah/36e4bbfc6d2412f26b172cac923a2ed4 to your computer and use it in GitHub Desktop.
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 | |
# Get all the resources that are assessible by me | |
# and order them by last modified date | |
# create a file, `resources.sh` with the content of this script | |
# and run `bash resources.sh` | |
AccountStore="accounts.csv" | |
ResourcegroupStore="resourcegroups.csv" | |
ResourceStore="resources.csv" | |
rm $AccountStore 2> /dev/null | |
rm $ResourcegroupStore 2> /dev/null | |
rm $ResourceStore 2> /dev/null | |
az login > /dev/null | |
az group list -o tsv --query "[].[id, name]" > $ResourcegroupStore | |
cat resourcegroups.csv | awk -F\t '{print $1}' | awk -F/ '{print $3}' | sort | uniq > $AccountStore | |
touch $ResourceStore | |
while read -r subscription; do | |
az resource list --subscription $subscription -o tsv --query '[].[createdTime, changedTime, type, id]' >> $ResourceStore | |
done < $AccountStore | |
TAB=`echo -e "\t"` | |
sort -t"$TAB" -k2 $ResourceStore | |
rm $AccountStore | |
rm $ResourcegroupStore | |
rm $ResourceStore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment