Created
January 28, 2011 21:44
-
-
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
This file contains 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
#!/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