Created
August 9, 2015 15:13
-
-
Save jodiecunningham/5466f1344b9b8c23c401 to your computer and use it in GitHub Desktop.
Shut down idle AWS plex instance
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 -x | |
#DEBUG=echo | |
# Runs via cron to shut down the instance if it's not in use for 5 minutes | |
# Starts checks after it's been up more than 500secs | |
# Won't kick you out if you're ssh'ed in and it's idle. | |
# crontab -l|grep idle | |
# */6 * * * * /root/bin/idle.sh >/dev/null 2>&1 | |
until $(awk '$1>500{exit 1}' /proc/uptime) | |
do | |
if [ $(sar -n DEV 300 1|awk '/eth0/{ if ($11<0.05){ exit 1;} exit 0; }') ] || [ $(ss -o state established '( sport = :ssh )'|wc -l) = 1 ]; | |
then | |
echo "$(date) Shutting down" >>/root/bin/idle.log; | |
${DEBUG} /sbin/poweroff; | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment