Skip to content

Instantly share code, notes, and snippets.

@vadirajks
Created July 14, 2022 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vadirajks/af4fbab888791066af5b758e65aa92b1 to your computer and use it in GitHub Desktop.
Save vadirajks/af4fbab888791066af5b758e65aa92b1 to your computer and use it in GitHub Desktop.
gcp un used disk
#!/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