I have a script using the following command to remove a folder:
ssh -q root@hostname sh -c 'rm -rf /opt/jetty/'
Most of the times it works fine, but occasionally I get this message:
rm: cannot remove `/opt/jetty': Directory not empty
The only suspicious point is the folder to delete contains a lock file which is being used by shell command flock
to acquire file lock. But I tried to remove the folder manually when the file was even being locked by flock
, it get succeeded.
update:
The environment is Linux
# uname -a
Linux XXX 2.6.32-504.8.1.el6.x86_64 #1 SMP Fri Dec 19 12:09:25 EST 2014 x86_64 x86_64 x86_64 GNU/Linux
rm didn't alias to anything, the out put of rm:
# rm
rm: missing operand
Try `rm --help' for more information.
I have a service script to start Jetty which creates a file lock inside the folder. Some snippet as shown below:
JETTY_LOCK=/opt/jetty/jetty_lock
start(){
#open file descriptor and acquire lock
exec 200>$JETTY_LOCK
flock -x -n 200 || { exec 200>&-;echo 'jetty is being started by another process.'; sleep 5; exit 0; }
...
cd /opt/jetty/
...
echo $!>&200
fi
flock -u 200 #release lock
exec 200>&- #close file descriptor
}
update:
After the error reproduced, I found only jetty_lock file was still remaining int /opt/jetty, does that mean flock
stops file lock from deleting? I cannot provide more details because I don't know when will it happen the next time...
rm
aliased to anything? What is the output oftype rm
? Please edit your question and add this information./opt/jetty/temp
, for starters.ssh -q root@hostname sh -c 'rm -rf /opt/jetty/ || ls -la /opt/jetty/'
, does it output anything?