Created
July 14, 2022 16:50
-
-
Save vadirajks/af4fbab888791066af5b758e65aa92b1 to your computer and use it in GitHub Desktop.
gcp un used disk
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 project=" | |
a | |
b | |
c | |
" | |
for p in $project; do | |
for disk in $(gcloud compute disks list --filter="-users:*" --format "csv(name,LOCATION)" --project "$p"); do | |
echo "deleting: ${disk}" | |
gcloud compute disks delete --zone=${disk##*,} --quiet ${disk%%,*} --project "$p" | |
done | |
done | |
#!/bin/bash | |
SlackChannelName=abc-channel | |
SlackHookURL="https://hooks.slack.com/services/abc-webhook" | |
MessageBody= | |
MessageTitle="CRITICAL:/custom-scripts/not_used_desk.sh($(hostname)/$(hostname -i))" | |
export project=" | |
a | |
b | |
c | |
" | |
for p in $project; do | |
disk=$(gcloud compute disks list --filter="-users:*" --format "table(name,LOCATION,SIZE_GB)" --project "$p") | |
echo "$disk" | |
if [ ! -z "$disk" ]; then | |
MessageBody=$(echo -e "PROJECT=$p\nNOT USED DISK:\n\`\`\`\n$disk\n\`\`\`") | |
[ -n "$MessageBody" ] && statusCode=$(bash -x /custom-scripts/postToSlack -t "$MessageTitle" -b "$MessageBody" -c "$SlackChannelName" -u "$SlackHookURL" -s "critical" ) && exit 0 | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment