Skip to content

Instantly share code, notes, and snippets.

@bitcloud
Created May 28, 2015 12:28
Show Gist options
  • Save bitcloud/52ba86060f815e9d9133 to your computer and use it in GitHub Desktop.
Save bitcloud/52ba86060f815e9d9133 to your computer and use it in GitHub Desktop.
If you have a TimeMachine on a NAS oder Linux Server, sometimes it tells you that the sparsbundle is already in use. This small script cleans up old AFP connections that are already dead. Change the PROCOWNER to the afpd root process owner.
#!/bin/bash
PROCOWNER=admin
for PID in $(ps waux | grep afpd | grep -v $PROCOWNER | awk '{print $1}')
do
echo "==> checking pid $PID";
lsof -i | grep afp | grep -v $PROCOWNER | awk '{print $2}' | grep $PID > /dev/null
if [ $? -ne 0 ];
then
ps waux | grep $PID | grep -v $PROCOWNER
#lsof | grep $PID | grep afpd | grep MD0_DATA
echo -n "! already dead. killing $PID ... "
kill $PID
PID=''
echo "done."
else
echo "still alive."
fi
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment