Skip to content

Instantly share code, notes, and snippets.

@allthingscode
Created January 28, 2011 21:44
Show Gist options
  • Save allthingscode/801044 to your computer and use it in GitHub Desktop.
Save allthingscode/801044 to your computer and use it in GitHub Desktop.
Sometimes it can be frustrating when you need to delete/rename/move a file via a samba file share, but you can't because it's locked by someone else. This script attempts to look up the IP address of all samba users that are currently using the file. S
#!/bin/bash
#
SCRIPT=${0##*/}
if [[ $# -ne 1 ]] ; then
echo "usage: $SCRIPT filename"
exit 192
fi
OUTPUT=`lsof "$1"`
if [[ -z "$OUTPUT" ]] ; then
echo "Nothing is using that file."
exit 0
fi
for PID in `lsof "$1" | awk '/smbd/{print $2}'` ; do
OUTPUT=`grep -Ril $PID /var/log/samba/`
OUTPUT=${OUTPUT##*/}
echo $OUTPUT
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment