Created
February 28, 2017 14:32
-
-
Save ryancdotorg/e008735609c6a1cbfb870100b4e99f2d to your computer and use it in GitHub Desktop.
shut down a system when it becomes idle - for aws spot instances
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 | |
IDLES=0 | |
while sleep 30 | |
do | |
PCT=`top -bn 2 -d 0.1 | grep '^%Cpu' | tail -n 1 | tr :. ' ' | awk '{print$2}'` | |
if [ $PCT -lt 10 ] | |
then | |
IDLES=$[$IDLES+1] | |
#echo $IDLES $PCT | |
else | |
IDLES=0 | |
fi | |
if [ $IDLES -ge 20 ] | |
then | |
sudo shutdown -h now | |
break | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment