The original file must retain intact but it should get empty. Actually, the contents needs to be processed by another process and for new entries, the file must remain there with zero records.
Note, however, that you have a built-in race condition...
If someone opens file1 for appending during the cp and then writes to that file descriptor:
the data may be copied into fie2 by the cp,
may be cleared by the > /dev/null never to be seen again,
or may appear in file1 after it has been cleared by the > /dev/null.
To get rid of this race condition, we need to know more about how processes writing to file1 open the file and how the permissions of processes writing to that file are related to the owner and group of the directory in which the target file resides.
The writers obviously have write permission to the target file. If they also have write permission in the directory in which it resides, the safe thing would be to use:
and have the writers open file1 with the flags:
guaranteeing (assuming no write errors) that data written to that file descriptor will appear either in file1 or file2.
If you can't do that; you need to block all writers to file1 while it is being rotated.
Hello every body,
Kindly support me to "copy a file without remove the contents of the target file"
Thanks in advance. :)
Ahmed Amer
Cairo,Egypt (2 Replies)
Instead of using an external Certification Authority CA such as Verisgn, in windows I have been told there is something called self ssl ( The server is its own Certification Authority)
In Solaris is there such an alternate?
In need it for apache.
Much appreciate for any guidence.
Thanks (2 Replies)
So tried:
cp -r -p test1/ user@machine:///srv/www/vhosts/domain.co.uk/httpdocs/backup/
but this didn't work either :(
Anyone able to help with this?
Many thanks
Mr M (3 Replies)
Hi,
I'm new to Unix. I want to read the all the lines from a text file and write the alternate lines into another file. Please give me a shell script solution.
file1
-----
one
two
three
four
five
six
seven
newfile(it should contain the alternate lines from the file1)
-------
one... (6 Replies)
Hi,
Is there any other command echo does.
if
I am doing this operation for each line in my file. So its taking very long time to process more than 1000 records.
Is there any alternative way to write the above if statement (5 Replies)
All,
I am new to unix and i have the following requirement.
I have file(s) landing into input directory with timestamp, first i want to copy all these files into seperate directory then i want to rename these files without timestamp and also remove header,trailer from that file..
Could... (35 Replies)
hi,
i encounter a quite a new things for me.
lets sat my test.txt modified date is 6th of July 2005.
then i execute the following command:
"cp test.txt testfolder/test.txt"
when i go to execute "ls -l" command...
the test.txt modified date become today date!
but if i execute:
... (5 Replies)