Skip to content

Instantly share code, notes, and snippets.

View kretes's full-sized avatar

Tomasz Bartczak kretes

View GitHub Profile
@JustinShenk
JustinShenk / idle-shutdown.sh
Last active January 22, 2024 20:45
Google Cloud Platform (GCP) instance idle shutdown
#!/bin/bash
# Add to instance metadata with `gcloud compute instances add-metadata \
# instance-name --metadata-from-file startup-script=idle-shutdown.sh` and reboot
# NOTE: requires `bc`, eg, sudo apt-get install bc
# Modified from https://stackoverflow.com/questions/30556920/how-can-i-automatically-kill-idle-gce-instances-based-on-cpu-usage
threshold=0.1
count=0
wait_minutes=60
while true