I have a polling script that will occasionally pop out the name of a file to delete. The file to delete will always be located on an NFS-mounted filesystem.
So I wrote this Bash script:
#!/bin/bash
/usr/local/bin/polling.sh |
while read FILE_TO_DELETE;
do
rm "${FILE_TO_DELETE}"
done
When this script is run, I get:
"cannot remove '/file/that/needs/deleting.txt': Device or resource busy".
If I run the rm command outside the while-read loop, it works just fine, so it's not a permission or open file issue.
Can anyone explain why the rm command doesn't work inside this loop but works fine outside of it?
FWIW, I looked at the file context before and after modifying the file, using ls -laZ, and they look the same. This is truly perplexing.