Last active
February 10, 2023 21:43
-
-
Save ryancdotorg/e31f7960cbba108191a64264d4e724aa 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 | |
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] | |
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