What is a "busy file? How can i delete in TCL script?

Hi,

I have a tcl script that generate a lot of intermediate files (and
folders). At the last step of my script, I've to clean the working
directory and keep only one or two files.

I have written a proc to clean work dir like this:

proc cleanWorkDir {dir keep1 {keep2 ""}} {
   set here [pwd]
   cd $dir
   if {$keep2 == "" } {
     set keep2 $keep1
   }

   foreach f [glob -nocomplain *] {
     if { ![string equal $f [getOnlyName $keep1] ] && ![string equal
$f [getOnlyName $keep2]] } {
     	file delete -force $f
     }
   }
   cd $here
}


Although it worked on my laptop, but on customer's Linux machine I
always get error message:
ERROR: cannot remove `A/B/.nfs00000000010d28ba00004dfb': Device or
resource busy
    while executing
  "file delete -force $f"
....


Despite of being able to delete the whole folder (Folder "A" in error
message) manually, I don't understand why cannot the TCL script do it!

Can anyone help me solve this?

Thanks,
Ahmad
0
Ahmad
11/4/2010 7:45:44 PM
comp.lang.tcl 23170 articles. 1 followers. Post Follow

9 Replies
656 Views

Similar Articles

[PageSpeed] 15

I have also noticed something.. When the TCL script exits after this
error, and I try to "ls" the ".nsf...." file it complains about, I
don't find it!

What is the .nsf file stands for? Who generates it?

Thanks,
Ahmad


On Nov 4, 12:45=A0pm, Ahmad <ahmad.abdulgh...@gmail.com> wrote:
> Hi,
>
> I have a tcl script that generate a lot of intermediate files (and
> folders). At the last step of my script, I've to clean the working
> directory and keep only one or two files.
>
> I have written a proc to clean work dir like this:
>
> proc cleanWorkDir {dir keep1 {keep2 ""}} {
> =A0 =A0set here [pwd]
> =A0 =A0cd $dir
> =A0 =A0if {$keep2 =3D=3D "" } {
> =A0 =A0 =A0set keep2 $keep1
> =A0 =A0}
>
> =A0 =A0foreach f [glob -nocomplain *] {
> =A0 =A0 =A0if { ![string equal $f [getOnlyName $keep1] ] && ![string equa=
l
> $f [getOnlyName $keep2]] } {
> =A0 =A0 =A0 =A0 file delete -force $f
> =A0 =A0 =A0}
> =A0 =A0}
> =A0 =A0cd $here
>
> }
>
> Although it worked on my laptop, but on customer's Linux machine I
> always get error message:
> ERROR: cannot remove `A/B/.nfs00000000010d28ba00004dfb': Device or
> resource busy
> =A0 =A0 while executing
> =A0 "file delete -force $f"
> ...
>
> Despite of being able to delete the whole folder (Folder "A" in error
> message) manually, I don't understand why cannot the TCL script do it!
>
> Can anyone help me solve this?
>
> Thanks,
> Ahmad

0
Ahmad
11/4/2010 7:54:20 PM
At Thu, 4 Nov 2010 12:54:20 -0700 (PDT) Ahmad <ahmad.abdulghany@gmail.com> wrote:

> 
> I have also noticed something.. When the TCL script exits after this
> error, and I try to "ls" the ".nsf...." file it complains about, I
> don't find it!
> 
> What is the .nsf file stands for? Who generates it?

NFS -- 'Network File System', a UNIX file sharing protocol, originally
invented by Sun Microsystems back in the late 1970's or so. The
".nsf...." file is something created by the NFS software, I think
related to locking.

> 
> Thanks,
> Ahmad
> 
> 
> On Nov 4, 12:45=A0pm, Ahmad <ahmad.abdulgh...@gmail.com> wrote:
> > Hi,
> >
> > I have a tcl script that generate a lot of intermediate files (and
> > folders). At the last step of my script, I've to clean the working
> > directory and keep only one or two files.
> >
> > I have written a proc to clean work dir like this:
> >
> > proc cleanWorkDir {dir keep1 {keep2 ""}} {
> > =A0 =A0set here [pwd]
> > =A0 =A0cd $dir
> > =A0 =A0if {$keep2 =3D=3D "" } {
> > =A0 =A0 =A0set keep2 $keep1
> > =A0 =A0}
> >
> > =A0 =A0foreach f [glob -nocomplain *] {
> > =A0 =A0 =A0if { ![string equal $f [getOnlyName $keep1] ] && ![string equa=
> l
> > $f [getOnlyName $keep2]] } {
> > =A0 =A0 =A0 =A0 file delete -force $f
> > =A0 =A0 =A0}
> > =A0 =A0}
> > =A0 =A0cd $here
> >
> > }
> >
> > Although it worked on my laptop, but on customer's Linux machine I
> > always get error message:
> > ERROR: cannot remove `A/B/.nfs00000000010d28ba00004dfb': Device or
> > resource busy
> > =A0 =A0 while executing
> > =A0 "file delete -force $f"
> > ...
> >
> > Despite of being able to delete the whole folder (Folder "A" in error
> > message) manually, I don't understand why cannot the TCL script do it!
> >
> > Can anyone help me solve this?
> >
> > Thanks,
> > Ahmad
> 
>                                                                                                     

-- 
Robert Heller             -- 978-544-6933 / heller@deepsoft.com
Deepwoods Software        -- http://www.deepsoft.com/
()  ascii ribbon campaign -- against html e-mail
/\  www.asciiribbon.org   -- against proprietary attachments


                                                                                                                           
0
Robert
11/4/2010 8:26:19 PM
Hi Robert,

This is a very nice to know, thank you.

Do you have any idea how can I force delete this kind of files?

Thanks,
Ahmad


On Nov 4, 1:26=A0pm, Robert Heller <hel...@deepsoft.com> wrote:
> At Thu, 4 Nov 2010 12:54:20 -0700 (PDT) Ahmad <ahmad.abdulgh...@gmail.com=
> wrote:
>
>
>
> > I have also noticed something.. When the TCL script exits after this
> > error, and I try to "ls" the ".nsf...." file it complains about, I
> > don't find it!
>
> > What is the .nsf file stands for? Who generates it?
>
> NFS -- 'Network File System', a UNIX file sharing protocol, originally
> invented by Sun Microsystems back in the late 1970's or so. The
> ".nsf...." file is something created by the NFS software, I think
> related to locking.
>
>
>
>
>
> > Thanks,
> > Ahmad
>
> > On Nov 4, 12:45=3DA0pm, Ahmad <ahmad.abdulgh...@gmail.com> wrote:
> > > Hi,
>
> > > I have a tcl script that generate a lot of intermediate files (and
> > > folders). At the last step of my script, I've to clean the working
> > > directory and keep only one or two files.
>
> > > I have written a proc to clean work dir like this:
>
> > > proc cleanWorkDir {dir keep1 {keep2 ""}} {
> > > =3DA0 =3DA0set here [pwd]
> > > =3DA0 =3DA0cd $dir
> > > =3DA0 =3DA0if {$keep2 =3D3D=3D3D "" } {
> > > =3DA0 =3DA0 =3DA0set keep2 $keep1
> > > =3DA0 =3DA0}
>
> > > =3DA0 =3DA0foreach f [glob -nocomplain *] {
> > > =3DA0 =3DA0 =3DA0if { ![string equal $f [getOnlyName $keep1] ] && ![s=
tring equa=3D
> > l
> > > $f [getOnlyName $keep2]] } {
> > > =3DA0 =3DA0 =3DA0 =3DA0 file delete -force $f
> > > =3DA0 =3DA0 =3DA0}
> > > =3DA0 =3DA0}
> > > =3DA0 =3DA0cd $here
>
> > > }
>
> > > Although it worked on my laptop, but on customer's Linux machine I
> > > always get error message:
> > > ERROR: cannot remove `A/B/.nfs00000000010d28ba00004dfb': Device or
> > > resource busy
> > > =3DA0 =3DA0 while executing
> > > =3DA0 "file delete -force $f"
> > > ...
>
> > > Despite of being able to delete the whole folder (Folder "A" in error
> > > message) manually, I don't understand why cannot the TCL script do it=
!
>
> > > Can anyone help me solve this?
>
> > > Thanks,
> > > Ahmad
>
> --
> Robert Heller =A0 =A0 =A0 =A0 =A0 =A0 -- 978-544-6933 / hel...@deepsoft.c=
om
> Deepwoods Software =A0 =A0 =A0 =A0--http://www.deepsoft.com/
> () =A0ascii ribbon campaign -- against html e-mail
> /\ =A0www.asciiribbon.org=A0 -- against proprietary attachments

0
Ahmad
11/4/2010 10:16:08 PM
At Thu, 4 Nov 2010 15:16:08 -0700 (PDT) Ahmad <ahmad.abdulghany@gmail.com> wrote:

> 
> Hi Robert,
> 
> This is a very nice to know, thank you.
> 
> Do you have any idea how can I force delete this kind of files?

I don't think you can OR should.

> 
> Thanks,
> Ahmad
> 
> 
> On Nov 4, 1:26=A0pm, Robert Heller <hel...@deepsoft.com> wrote:
> > At Thu, 4 Nov 2010 12:54:20 -0700 (PDT) Ahmad <ahmad.abdulgh...@gmail.com=
> > wrote:
> >
> >
> >
> > > I have also noticed something.. When the TCL script exits after this
> > > error, and I try to "ls" the ".nsf...." file it complains about, I
> > > don't find it!
> >
> > > What is the .nsf file stands for? Who generates it?
> >
> > NFS -- 'Network File System', a UNIX file sharing protocol, originally
> > invented by Sun Microsystems back in the late 1970's or so. The
> > ".nsf...." file is something created by the NFS software, I think
> > related to locking.
> >
> >
> >
> >
> >
> > > Thanks,
> > > Ahmad
> >
> > > On Nov 4, 12:45=3DA0pm, Ahmad <ahmad.abdulgh...@gmail.com> wrote:
> > > > Hi,
> >
> > > > I have a tcl script that generate a lot of intermediate files (and
> > > > folders). At the last step of my script, I've to clean the working
> > > > directory and keep only one or two files.
> >
> > > > I have written a proc to clean work dir like this:
> >
> > > > proc cleanWorkDir {dir keep1 {keep2 ""}} {
> > > > =3DA0 =3DA0set here [pwd]
> > > > =3DA0 =3DA0cd $dir
> > > > =3DA0 =3DA0if {$keep2 =3D3D=3D3D "" } {
> > > > =3DA0 =3DA0 =3DA0set keep2 $keep1
> > > > =3DA0 =3DA0}
> >
> > > > =3DA0 =3DA0foreach f [glob -nocomplain *] {
> > > > =3DA0 =3DA0 =3DA0if { ![string equal $f [getOnlyName $keep1] ] && ![s=
> tring equa=3D
> > > l
> > > > $f [getOnlyName $keep2]] } {
> > > > =3DA0 =3DA0 =3DA0 =3DA0 file delete -force $f
> > > > =3DA0 =3DA0 =3DA0}
> > > > =3DA0 =3DA0}
> > > > =3DA0 =3DA0cd $here
> >
> > > > }
> >
> > > > Although it worked on my laptop, but on customer's Linux machine I
> > > > always get error message:
> > > > ERROR: cannot remove `A/B/.nfs00000000010d28ba00004dfb': Device or
> > > > resource busy
> > > > =3DA0 =3DA0 while executing
> > > > =3DA0 "file delete -force $f"
> > > > ...
> >
> > > > Despite of being able to delete the whole folder (Folder "A" in error
> > > > message) manually, I don't understand why cannot the TCL script do it=
> !
> >
> > > > Can anyone help me solve this?
> >
> > > > Thanks,
> > > > Ahmad
> >
> > --
> > Robert Heller =A0 =A0 =A0 =A0 =A0 =A0 -- 978-544-6933 / hel...@deepsoft.c=
> om
> > Deepwoods Software =A0 =A0 =A0 =A0--http://www.deepsoft.com/
> > () =A0ascii ribbon campaign -- against html e-mail
> > /\ =A0www.asciiribbon.org=A0 -- against proprietary attachments
> 
>                                                                                                         

-- 
Robert Heller             -- 978-544-6933 / heller@deepsoft.com
Deepwoods Software        -- http://www.deepsoft.com/
()  ascii ribbon campaign -- against html e-mail
/\  www.asciiribbon.org   -- against proprietary attachments


                                                                                                             
0
Robert
11/4/2010 11:56:45 PM
Your script is trying to delete all files in a directory except those 
you specify. It would probably be better to maintain a list of the 
temporary files and just loop through the list at the end deleting them, 
that way you avoid trying to delete other files (like the NFS lock files).

Simon


On 04/11/2010 23:56, Robert Heller wrote:
> At Thu, 4 Nov 2010 15:16:08 -0700 (PDT) Ahmad<ahmad.abdulghany@gmail.com>  wrote:
>
>>
>> Hi Robert,
>>
>> This is a very nice to know, thank you.
>>
>> Do you have any idea how can I force delete this kind of files?
>
> I don't think you can OR should.
>
>>
>> Thanks,
>> Ahmad
>>
>>
>> On Nov 4, 1:26=A0pm, Robert Heller<hel...@deepsoft.com>  wrote:
>>> At Thu, 4 Nov 2010 12:54:20 -0700 (PDT) Ahmad<ahmad.abdulgh...@gmail.com=
>>> wrote:
>>>
>>>
>>>
>>>> I have also noticed something.. When the TCL script exits after this
>>>> error, and I try to "ls" the ".nsf...." file it complains about, I
>>>> don't find it!
>>>
>>>> What is the .nsf file stands for? Who generates it?
>>>
>>> NFS -- 'Network File System', a UNIX file sharing protocol, originally
>>> invented by Sun Microsystems back in the late 1970's or so. The
>>> ".nsf...." file is something created by the NFS software, I think
>>> related to locking.
>>>
>>>
>>>
>>>
>>>
>>>> Thanks,
>>>> Ahmad
>>>
>>>> On Nov 4, 12:45=3DA0pm, Ahmad<ahmad.abdulgh...@gmail.com>  wrote:
>>>>> Hi,
>>>
>>>>> I have a tcl script that generate a lot of intermediate files (and
>>>>> folders). At the last step of my script, I've to clean the working
>>>>> directory and keep only one or two files.
>>>
>>>>> I have written a proc to clean work dir like this:
>>>
>>>>> proc cleanWorkDir {dir keep1 {keep2 ""}} {
>>>>> =3DA0 =3DA0set here [pwd]
>>>>> =3DA0 =3DA0cd $dir
>>>>> =3DA0 =3DA0if {$keep2 =3D3D=3D3D "" } {
>>>>> =3DA0 =3DA0 =3DA0set keep2 $keep1
>>>>> =3DA0 =3DA0}
>>>
>>>>> =3DA0 =3DA0foreach f [glob -nocomplain *] {
>>>>> =3DA0 =3DA0 =3DA0if { ![string equal $f [getOnlyName $keep1] ]&&  ![s=
>> tring equa=3D
>>>> l
>>>>> $f [getOnlyName $keep2]] } {
>>>>> =3DA0 =3DA0 =3DA0 =3DA0 file delete -force $f
>>>>> =3DA0 =3DA0 =3DA0}
>>>>> =3DA0 =3DA0}
>>>>> =3DA0 =3DA0cd $here
>>>
>>>>> }
>>>
>>>>> Although it worked on my laptop, but on customer's Linux machine I
>>>>> always get error message:
>>>>> ERROR: cannot remove `A/B/.nfs00000000010d28ba00004dfb': Device or
>>>>> resource busy
>>>>> =3DA0 =3DA0 while executing
>>>>> =3DA0 "file delete -force $f"
>>>>> ...
>>>
>>>>> Despite of being able to delete the whole folder (Folder "A" in error
>>>>> message) manually, I don't understand why cannot the TCL script do it=
>> !
>>>
>>>>> Can anyone help me solve this?
>>>
>>>>> Thanks,
>>>>> Ahmad
>>>
>>> --
>>> Robert Heller =A0 =A0 =A0 =A0 =A0 =A0 -- 978-544-6933 / hel...@deepsoft.c=
>> om
>>> Deepwoods Software =A0 =A0 =A0 =A0--http://www.deepsoft.com/
>>> () =A0ascii ribbon campaign -- against html e-mail
>>> /\ =A0www.asciiribbon.org=A0 -- against proprietary attachments
>>
>>
>

0
Simon
11/5/2010 10:14:08 AM
On Nov 4, 4:56=A0pm, Robert Heller <hel...@deepsoft.com> wrote:
> At Thu, 4 Nov 2010 15:16:08 -0700 (PDT) Ahmad <ahmad.abdulgh...@gmail.com=
> wrote:
>
>
>
> > Hi Robert,
>
> > This is a very nice to know, thank you.
>
> > Do you have any idea how can I force delete this kind of files?
>
> I don't think you can OR should.
>
>

I agree with Robert that the lock files can't be deleted. The first
question you should have is why are they being created. Is there some
good reason that the files you have created are being locked by a
remote host? If not then I would spend some time figuring what the
heck is going on. Second, the /tmp directory on unix/linux is where
you should be putting all your temporary files. This directory is
cleared when a system is rebooted which will remove any abandoned lock
files. In a large network it is possible for lock files to become
abandoned which is a real headacke because they will prevent
directories from being deleted.

tomk
0
tomk
11/5/2010 4:10:28 PM
On 5 nov, 17:10, tomk <krehbiel....@gmail.com> wrote:
> On Nov 4, 4:56=A0pm, Robert Heller <hel...@deepsoft.com> wrote:
>
> > At Thu, 4 Nov 2010 15:16:08 -0700 (PDT) Ahmad <ahmad.abdulgh...@gmail.c=
om> wrote:
>
> > > Hi Robert,
>
> > > This is a very nice to know, thank you.
>
> > > Do you have any idea how can I force delete this kind of files?
>
> > I don't think you can OR should.
>
> I agree with Robert that the lock files can't be deleted. The first
> question you should have is why are they being created. Is there some
> good reason that the files you have created are being locked by a
> remote host? If not then I would spend some time figuring what the
> heck is going on. Second, the /tmp directory on unix/linux is where
> you should be putting all your temporary files. This directory is
> cleared when a system is rebooted which will remove any abandoned lock
> files. In a large network it is possible for lock files to become
> abandoned which is a real headacke because they will prevent
> directories from being deleted.
>
> tomk

To see the file you should propbaly try
ls -al
This lists all files including hidden ones, under Linux the . before a
filename will hide them from simple ls

You should probably be creating a private tmp directory in /tmp to
keep all your files together then a simple delete of the directory
should clean up easily.


Martyn
0
MSEdit
11/5/2010 5:51:22 PM
* Robert Heller <heller@deepsoft.com>
| > What is the .nsf file stands for? Who generates it?
>
| ... The ".nsf...." file is something created by the NFS software, I
| think related to locking.

Those .nfs files are not related to file locking, but to removed files
on an NFS share which are still open in some application.

See
  https://www.cs.indiana.edu/Facilities/FAQ/General/dotnfs.html
  http://www.unix.com/filesystems-disks-memory/5702-removing-nfs-files.html

HTH
R'
0
Ralf
11/5/2010 6:59:48 PM
@Ahmad

may be one more tip is you can use exception handling if script is
actually aborting without completion where you can use tcl catch
statement for file delete operation and print messages when some cases
it fails as busy etc.
0
SANKY
11/11/2010 1:13:30 PM
Reply: