Skip to content

Instantly share code, notes, and snippets.

@ryancdotorg
Last active February 10, 2023 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryancdotorg/e31f7960cbba108191a64264d4e724aa to your computer and use it in GitHub Desktop.
Save ryancdotorg/e31f7960cbba108191a64264d4e724aa to your computer and use it in GitHub Desktop.
#!/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