Created
March 19, 2020 05:15
-
-
Save meain/c26975ccb74b3db98d970dc99d831f90 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/sh | |
# Automatically turn off a system if no ssh connection is found in last 1hr | |
set -e | |
if last | grep "still logged in";then | |
exit 0 | |
fi | |
LAST_ACCESS="$(stat -c'%X' /var/log/wtmp)" | |
CURRENT_TIME="$(date +%s)" | |
DIFF="$((CURRENT_TIME-LAST_ACCESS))" | |
if [ $DIFF -ge 3600 ];then | |
sudo shutdown | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment