Created
June 24, 2019 12:55
-
-
Save odiak/b1e809458bdb885ab9bbd3d58b6616d5 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 | |
TIMESTAMP_FILE="/tmp/auto-stop-timestamp" | |
if [ $(who | wc -l) -gt 0 ]; then | |
rm -f $TIMESTAMP_FILE | |
else | |
now=$(date "+%s") | |
if [ -f "$TIMESTAMP_FILE" ]; then | |
echo $now > $TIMESTAMP_FILE | |
else | |
t=$(cat $TIMESTAMP_FILE) | |
if [ $(($now - $t)) -gt 3600 ]; then | |
gcloud compute instances stop my-instance-name | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment