Skip to main content
Became Hot Network Question
Adding extra info from the comments.
Source Link
Giacomo1968
  • 59.1k
  • 23
  • 180
  • 225

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.

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?

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.

added 75 characters in body
Source Link

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?

I have a polling script that will occasionally pop out the name of a file to delete. 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?

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?

added 4 characters in body
Source Link

I have a polling script that will occasionally pop out the name of a file to delete. 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'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?

I have a polling script that will occasionally pop out the name of a file to delete. 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': 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?

I have a polling script that will occasionally pop out the name of a file to delete. 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?

edited body
Source Link
Giacomo1968
  • 59.1k
  • 23
  • 180
  • 225
Loading
deleted 7 characters in body; edited title
Source Link
Giacomo1968
  • 59.1k
  • 23
  • 180
  • 225
Loading
Source Link
Loading