Skip to content

Instantly share code, notes, and snippets.

@amcginlay
Created July 27, 2020 17:17
Show Gist options
  • Save amcginlay/1f9ab2c266b7a00a041a7c087445e469 to your computer and use it in GitHub Desktop.
Save amcginlay/1f9ab2c266b7a00a041a7c087445e469 to your computer and use it in GitHub Desktop.
#!/bin/bash
aws iam get-account-authorization-details --query "RoleDetailList[].[RoleLastUsed.LastUsedDate, RoleName]" --output text | sed -e 's/^None/1970-01-01T00:00:00+00:00/g' | sort | while read roledata; do
set $roledata; rolelastused=${1:0:10}; rolename=${2}
daysago=$((($(date +%s)-$(date -j -f "%Y-%m-%d" ${rolelastused} +%s))/86400))
echo "${rolename} (used ${daysago} days ago)"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment