Last active
July 28, 2019 00:44
-
-
Save sergsoares/3fb347325ed4a335cc3e2314d6652fbe to your computer and use it in GitHub Desktop.
Simple script to shutdown after SSH iddle.
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 | |
| IDLE_SSH_CONNECTIONS=$(cat .shutdown-counter) | |
| QUANTITY_OF_CONNECTION=$(who | wc -l) | |
| echo "Idle: $IDLE_SSH_CONNECTIONS" | |
| echo "Who logged: $QUANTITY_OF_CONNECTION" | |
| if [ $IDLE_SSH_CONNECTIONS -gt 30 ]; then | |
| echo 0 > .shutdown-counter | |
| echo 'Shutdown executed' | |
| sudo shutdown now | |
| elif [ $QUANTITY_OF_CONNECTION -gt 0 ]; then | |
| echo 'Reseting shutdown counter' | |
| echo 0 > .shutdown-counter | |
| else | |
| echo 'Adding 1 minute to iddle time.' | |
| echo $(expr $IDLE_SSH_CONNECTIONS + 1) > .shutdown-counter | |
| fi | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One Line solution: