Skip to content

Instantly share code, notes, and snippets.

@sj14
Last active March 10, 2024 09:23
Show Gist options
  • Save sj14/7c674b870641c4635fc0f904a0699e57 to your computer and use it in GitHub Desktop.
Save sj14/7c674b870641c4635fc0f904a0699e57 to your computer and use it in GitHub Desktop.
Shutdown only when no smb connection is open
#!/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