Operating System - HP-UX
1752542 Members
5463 Online
108788 Solutions
New Discussion юеВ

Re: redirect a tracefile to a null device

 
Wenth Leopold
Occasional Advisor

redirect a tracefile to a null device

i have a process which is constantly
writing data into a trace file
that trace file is the filling up my partition
till i find the reason which should stop the
filling up of the file
i need to temporarily redirect it to a null device WITHOUT stopping the process

is that possible ??
what kind of unixcommands to be used ?
stay small think large
10 REPLIES 10
SKR_1
Trusted Contributor

Re: redirect a tracefile to a null device

do

> file name

It will trim your file.

Thanks

SKR
Fabio Ettore
Honored Contributor

Re: redirect a tracefile to a null device

Hi,

I think it depends on process, for example if there is a configuration file for that process it should be easy to change log file for it to /dev/null. Otherwise it sounds not possible to change the behaviour of a process which per default writes in a exact trace file.

Anyway could you say which is the process?

Best regards,
Fabio
WISH? IMPROVEMENT!
Steven E. Protter
Exalted Contributor

Re: redirect a tracefile to a null device

Shalom,

I think you need to change how the process is launched.

Messing with the process after it has already launched is likely to crash it. I assume its important or you would have simply killed it and restarted it.

If you don't want the file, don't launch with the output to a trace file.

If you do want the trace file, change the next launch of the process to put it in a place where there is sufficient space for it.

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
Dennis Handly
Acclaimed Contributor

Re: redirect a tracefile to a null device

As SEP says, it may be very difficult to do this.

You might try going into the debugger and changing the __iob entry for the particular stream but you would have to find it.
If you used open(2) instead of fopen(3), you could do something similar.

Basically you would have to weigh the cost of stopping the application and reprogramming it to do what you want, vs trying to fiddle with the debugger in assembly mode.
James R. Ferguson
Acclaimed Contributor

Re: redirect a tracefile to a null device

Hi Wenth:

You could do something as simple as this, without interrupting your process. Let's assume that your tracefile is named "mylog":

# cp ./mylog /path/mylog.old && > ./mylog

This preserves the data you have collect, but moves it to potentially another filesystem and then truncates the existing collection while allowing logging to continue. Note the use of 'cp' and *not* 'mv'.

Regards!

...JRF...
Rasheed Tamton
Honored Contributor

Re: redirect a tracefile to a null device

>i need to temporarily redirect it to a null device WITHOUT stopping the process

If you do not want to stop the running process now, then the workaround is, as SKR suggested, empty the output trace file which fills the partition, using a small script like below:

while:
do
cat /dev/null > /path/trace-output-file
sleep 1
done
TTr
Honored Contributor

Re: redirect a tracefile to a null device

> i need to temporarily redirect it to a null device WITHOUT stopping the process

The key words here are "WITHOUT stopping the proccess". You have to check how the process is using the trace file. You can use "fuser ". If the trace file is always kept open by the process, nulling the file as suggested above will either HUNG the process or delete the file but NOT recover the space. If the process opens the file, posts output to it and closes the file until next time, it is safe to null the file.
James R. Ferguson
Acclaimed Contributor

Re: redirect a tracefile to a null device

Hi (again) Wenth:

> TTr: nulling the file as suggested above will either HUNG the process or delete the file but NOT recover the space.

That's not true, By truncating the file, the disk blocks formerly in use are returned to the system, thereby recovering the space formerly used. The process writing to the file can continue unabated.

Regards!

...JRF...
TTr
Honored Contributor

Re: redirect a tracefile to a null device

JRF,

I said, "IF the tracefile is kept open by the process..."

Would you run your commands to the syslog.log file?