moving a file while is being written
Hi again.
Well, this is rather a theoretical question and it's not urgent - I don't want to abuse anyone's time. Let's say a file ("myfile", in this case) is open for writing from a shell, by something like : Code:
cat [SOME-HUGE-FILE] > myfile Code:
mv myfile myfile2 Thanks for reading! |
You can easily check by yourself, the ongoing process will keep on writing to the newly renamed file, assuming is stays on the same filesystem.
By the way, C++ knowledge is unrelated. Open and write are written in C, and the file system implementation is what matters here. |
Great, thanks. These are actually very good news for me. I was afraid that the redirected output would be completely lost.
Thank you. |
easy to test yourself:
xterm 1 cat - > file1 start typing a bit xterm2 mv file1 file2 xterm1 ctrl-D (same directory of course ;) |
Yep; it works. Thanks :)
|
I'll post this here; no need to start another thread for the next question - which is related to this discussion.
Let's say I continuously redirect the output of some command to a file; be it "tail -f". Code:
tail -f mainfile > outfile I tried redirecting to a symbolic lynk, and then to force the re-creation of that link, like this: Code:
touch outfile1 Maybe if I'll instantly truncate outfile1 after copying it to outfile2 would do, though copying takes time and there won't be some way of telling if any new line was appended to outfile1 between those two actions.:study: If anyone has any idea I'll be most grateful - I hope someone has some more knowledge about what happens underneath the filesystem than me; cheers. |
You can't do that when your output goes directly to a file. The solution is to use an intermediary program like rotatelogs or cronolog: http://httpd.apache.org/docs/2.0/pro...otatelogs.html http://cronolog.org/
|
Quote:
Quote:
Code:
middle() { Thanks! |
if you are writing to log files you can use the
logger (1) utility which adds times etc. for you. we have to accept some limitations. I admit though I never use it myself ;) |
or even something silly like this:
Code:
LOGFILE=blah.log |
Well, I'm not altering the log files, but your advices are always welcome.
I'm rather continuously watching / backing them up. What kinda worries me is that if I watch them with tail -f, they will be checked for line additions one per second (this is the default). If one or more lines are added within this ONE second and a log rotating mechanism interferes - and moves the file (and having tail following the filename), these lines will be lost. So I probably should be using something like: Code:
tail -f --follow=name --sleep-interval=0 Just a thought - maybe I sound paranoid. Thanks. |
All times are GMT -5. The time now is 10:05 AM. |