Created
October 15, 2022 17:54
-
-
Save jim80net/be23439647bc0d182a18641bc79e373b to your computer and use it in GitHub Desktop.
Shutdown idle EC2 jumpbox
This file contains hidden or 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 | |
set -eu -o pipefail | |
[[ $(w | wc -l) -lt 3 ]] && { | |
echo "Nobody logged in" | |
sudo shutdown -hP +60 "Shutting down due to no active sessions" | |
} || { | |
echo "Users logged in" >/dev/null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment