Last active
March 10, 2024 09:23
-
-
Save sj14/7c674b870641c4635fc0f904a0699e57 to your computer and use it in GitHub Desktop.
Shutdown only when no smb connection is open
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
#!/usr/bin/env bash | |
set -o xtrace # output every line which gets executed | |
set -o nounset # fail if an unset variable is used | |
#set -o errexit # fail if a command exits with non-zero | |
set -o pipefail # fail if a command in a pipe fails | |
COUNTER=0 | |
while test $COUNTER -le 30 | |
do | |
sleep 60 | |
SMB_CONNS=$(pgrep --full --count "smbd: client") | |
if test $SMB_CONNS -gt 0 | |
then | |
echo "$SMB_CONNS connections open" | |
COUNTER=0 | |
continue | |
fi | |
COUNTER=$(( $COUNTER + 1 )) | |
done | |
echo "poweroff" | |
sudo poweroff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment