Last active
June 22, 2018 19:17
-
-
Save rrotter/e07b5e734edbf51fbe390e2eede9db2e to your computer and use it in GitHub Desktop.
Run this out of root cron to shut down inactive server
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 | |
# true if console users are idle or non-existant | |
function no_active_users() | |
{ | |
if [ `w -sh | sed 's/\s\{1,\}/\t/g' | cut -f4 | egrep '^[0-9\:\.s]+$' | wc -l` -eq 0 ] | |
then | |
return 0 | |
fi | |
return 1 | |
} | |
# true if 1, 5, and 15 minute load averages are all 0.00 | |
function no_active_process() | |
{ | |
cut -d' ' -f1,2,3 /proc/loadavg >> /tmp/idlr | |
if [[ `cut -d' ' -f1,2,3 /proc/loadavg` == '0.00 0.00 0.00' ]] | |
then | |
return 0 | |
fi | |
return 1 | |
} | |
if no_active_users | |
then | |
if no_active_process | |
then | |
shutdown -h now | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment