#!/bin/sh
for USER in $(ps ho user:20 $(pgrep ^gocryptfs) | awk '{print $1}'); do
  PROCESSCOUNT=$(pgrep -U "${USER}" | wc -l)
  if [ ! "${PROCESSCOUNT}" -gt 2 ]; then
    logger "gocryptfs for user ${USER} but no other processes - killing"
    pkill -u "$USER" -f gocryptfs
  fi
done
