Created
June 30, 2016 14:10
Revisions
-
charles-cooper created this gist
Jun 30, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ #!/bin/sh # This script, intended to be run as a cron job, checks if there are any logins or recent logins and shuts down if there are none. It is not intended to be portable and was written on a Ubuntu 16.04 machine. last_login_time=$(grep "systemd-logind" /var/log/auth.log | perl -pe "s/ ip.*//" | tail -1 | date --file=/dev/stdin +%s) if [ $(($cur_time - $last_login_time)) -ge 3600 ] && [ $(who | wc -l) -eq 0 ] then init 0 else echo 'current logins:' > /home/ubuntu/logins who >> /home/ubuntu/logins fi