whats wrong with mv ?

[code]
mv *old_file new_file*
touch *old_file*
[/code]

not sure if this will cause data loss, but if you know the source of the log
(some script ?), then check the existence of old_file prior to the log
action

[code]
if [ -a old_file ]
then
# log into old file
else
# log into temp file
[/code]

if temp contained any lines (or existed at all), these are the lost data,
and since its the main concern here, this might help you to check whether a
method is appropriate.
if you dont know the source of the log, you may try
[code]
grep -r old_file / | grep -i log
[/code]

On Tue, May 12, 2009 at 4:30 PM, Husam <[email protected]> wrote:

> in case of move there wont be an old file
>
> On Tue, May 12, 2009 at 4:24 PM, Aram Yegenian <[email protected]>wrote:
>
>>
>>
>> Hi Yaman,
>>
>> Just out of the top of my head coz I just woke up... Why not use mv, coz
>> mv is atomic and any process that still has access to the file would still
>> be able to write to the old file until you restart that process.
>>
>> --- On Tue, 5/12/09, Yaman Saqqa <[email protected]> wrote:
>>
>> > From: Yaman Saqqa <[email protected]>
>> > Subject: [JoLUG-General] Question on cp
>> > To: [email protected]
>> > Date: Tuesday, May 12, 2009, 3:13 PM
>> > Hello Luggers,
>> >
>> > A quick question.
>> >
>> > Let's say I wanna rotate a log file upon reaching a
>> > certain size and the file name is time dependent. logrotate
>> > configuration wildcards will not help, so I'm writing a
>> > script to do it, my questions is, as per the pseudo below
>> >
>> >
>> >
>> > every x time
>> > check file size
>> > if size > y
>> > cp oldfile oldfile-1 && echo > oldfile #
>> > (copy-truncate) because processes have open fd's with
>> > oldfile
>> > fi
>> >
>> > If the file size is large, cp WILL take some time and
>> > CONCURRENTLY data is still being written to the oldfile.
>> > Will cp cater to every byte written to the oldfile up
>> > until the micro-second "&& echo kicks in"?
>> > Or will there be data loss?
>> >
>> >
>> >
>> > Thanks!
>> >
>> > --
>> > abulyomon
>> >
>> > www.KiLLTHeUPLiNK.com
>> >
>> >
>> >
>> >
>> >
>> >
>> > >
>> >
>> >
>> >
>>
>>
>>
>>
>>
>>
>
>
> --
> Husam Habannakeh
> +971 5055 164 89 Dubai
> +962 777 656 086 Amman
> +966 5611 54 798 Riyadh
> Sent from Riyadh, 01, Saudi Arabia
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
### Jordan Linux Users Group ###
http://Jolug.org/
http://groups.google.com/group/Jolug

### Ubuntu Jordan LoCo Team ###
https://wiki.ubuntu.com/JordanTeam
http://lists.ubuntu.com/ubuntu-jo

### Ojuba Linux ### 
http://ojuba.org/

### Jordan PHP ###
http://groups.google.com/group/JoPHP
-~----------~----~----~----~------~----~------~--~---

رد على