Hai,
I have a program which updates the result in a log file, as the program runs 24*7,the size of log file keeps on increasing.
Can you help me with a shell command which will clear the content of a log file in use.
1) I tried tail -10 logfile > logfile ( the content is not changed )
2) > logfile ( no change in filesize )
3) echo -n >logfile ( no change in filesize )
Coolbhai,
If the way your application was designed, it is appending to the file
each microsecond, you must take the risk of loosing some data whenever
you refresh the log file.
If you are appending, then if the file does not exist, the append
will create it.
Here is one possible solution if you want to save the file:
result : no change in file size ,for a fraction of a second,file size droped to zero but again regained its original size.
I have a wierd suggestions:
I know the 'fuser' of that particluar file, is there any way by which that I transfer 'fuser' to temp-file and clear the logfile and bring the fuser back to actual logfile.
NB : Even if I rename the file,the renamed file keeps on updating.So process Id has some role in this process.
Assuming that the author of the code writing the never-ending file knows even a little bit about unix:
For this process there is a configuration file, which names the output logfile.
The process "reconfigures" itself when it receives a SIGHUP signal,
by re-reading the config file, and if the name of the logfile changed, then close the old one, open the new one.
This is pretty much UNIX standard for a never-ending log writer program.
Edit the config file, change the log file to another different name.
Send SIGHUP to the process when you are logged in as root.
truncate the old big file.