Re: Deleting a file while other script still appending to



On Feb 7, 2008 5:54 AM, Mahdi A Sbeih <mahdi.sbeih@xxxxxxx> wrote:
Hi all,

I have a script that logs activities to a txt log file. I noticed that
when deleting the file from another window or shell, the script stops
writing to the file. I was expecting something like the unix shell,
which is creating a new file and appending to it.
snip
After few seconds, and from another terminal, delete the file that was
created by the script, notice that the script won't stop or error out,
but in the same time no new file is created.
snip

When you unlink* a file you are telling the filesystem that the name
that is associated with that inode should no longer be used, but the
space is not reclaimed so long as there is still a reference to the
inode. This reference can be another link created by the link syscall
or an open file handle. A common trick used by daemons is to open
temporary files in read/write mode and then unlink them. By doing
this they can ensure that no other process can read or write to the
file. This is what is happening to you. What you need to do is open
the file for appending right before each write and close it right
after the write.

* There is no such thing as delete in POSIX filesystems; normally it
doesn't matter, but in this case you need to understand what is really
happening.
.



Relevant Pages

  • Re: detect shell script language
    ... In the 'old' days, when a user typed in a command, the interactive shell would immediately pass it off to 'exec' to execute. ... So, on return from exec with an error status, the shell would fork a copy of itself to try and run the script. ... As a result of the above, it was hard to tell whether the script was a Bourne shell or C shell, so the convention was introduced of using the Bourne shell no op command, as the first line in a Bourne shell script. ...
    (Debian-User)
  • Re: Call for input on comp.unix.shell FAQ
    ... >> questions and just tell people to FAQ it. ... The other level is how to write shell scripts. ... How can I remove whitespace characters within file names? ... Why one shouldn't use "echo" in a script? ...
    (comp.unix.shell)
  • SHELLdorado Newsletter 1/2003 - July 6th, 2003
    ... The "SHELLdorado Newsletter" covers UNIX shell script related ...
    (comp.unix.questions)
  • SHELLdorado Newsletter 1/2003 - July 6th, 2003
    ... The "SHELLdorado Newsletter" covers UNIX shell script related ...
    (comp.unix.shell)
  • Re: Affecting Institutional Change (Yeah Right)
    ... provides labs in most non-dorm buildings replete with the wonderful ... be run from a shell, no idea what an executable was, and, in fact, ... IDE program, go through a ton of menus to pick the right script, go ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)