1820047 Members
3407 Online
109608 Solutions
New Discussion юеВ

Re: truncate huge file

 
SOLVED
Go to solution
akkosh
Advisor

truncate huge file

dears

I have a program running under unix which needs to trace too many actions done by the system each 15minutes
this leads the trace file become very huge in no time.
sometime it may exceed 3GB in 30 minutes

I tried to redirect the file to /dev/null but it couldn't do the job.

My question : is there a way that i can configure a script to continuously truncate the file for example each minute so that i can keep the file empty all the time.

thanks so much
5 REPLIES 5
Pete Randall
Outstanding Contributor
Solution

Re: truncate huge file

> I tried to redirect the file to /dev/null but it couldn't do the job.

In what way could this not do the job? Any error message? Any symptoms that you can share with us?


Pete

Pete
Patrick Wallek
Honored Contributor

Re: truncate huge file

>>is there a way that i can configure a script
>>to continuously truncate the file for
>>example each minute so that i can keep the
>>file empty all the time

If you are going to do this, why have the information logged to the file at all? Why not just modify the program so that it sends it output to /dev/null.

If you insist on trying to clean out the file, try:

# > filename

If that did not work, what did it do?

To run that regularly, just set it up in cron.

* * * * * > filename

Will runn the command every minute of every hour of every day.
James R. Ferguson
Acclaimed Contributor

Re: truncate huge file

Hi:

I have to believe that you mean the file is written to with such a frequency that you never find an instant when it's empty. As Patrick suggested, have the process redirect its output to '/dev/null' or cron a redirection of '/dev/null' to the logfile periodically. A cron entry to truncate the log every minute would look like:

* * * * * cat /dev/null > /path/to/mylog

Regards!

...JRF...
Steven E. Protter
Exalted Contributor

Re: truncate huge file

Shalom,

It would be helpful to see the actual code or cron entry you are running.

You will regret it but you can set up cron to > filename and run it regularly. Potential pitfall there is if there is an open file handle or file I/O happening on the file. Then you might get into an I/O wait state.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
akkosh
Advisor

Re: truncate huge file

Thanks all for your help ...
i think it was my mistake that i was doing the /dev/null in a wrong way ...
I didn't know that i had to remove the file first and then create the link using
ln -s /dev/null ./

thanks all for your help and sure thanks all for your time