1825780 Members
2430 Online
109687 Solutions
New Discussion

Re: Trim the logfile

 
SOLVED
Go to solution
gany59
Regular Advisor

Trim the logfile

Hi Techiees

In one of the server /tmp is 100% .. i checked out in the server , one logfile is occupying more space , so i need to trim the lines of the file, so how to find how many lines are there in that file and if i need to delete the first 1000 lines , what i have to do ?

Could anybody tell this .. Thanks in advance..
11 REPLIES 11
Ganesan R
Honored Contributor

Re: Trim the logfile

Hi,

First up all, if any process is using the file currently, then you won't be able to release the space used by the log file.

#cat filename |wc -l

This will give you the lines in that file.

Check if any process is using that file.
#fuser -u

If no process is using the file just zip it.

#gzip filename
Best wishes,

Ganesh.
James R. Ferguson
Acclaimed Contributor

Re: Trim the logfile

Hi:

You can use:

# wc -l filename

...to return a count of the number of lines in the file.

To delete the first 1000 lines, you could do:

# sed -e '1,1000d' filename > filename.new
# mv filename.new filename

Regards!

...JRF...
Roopesh Francis_1
Trusted Contributor

Re: Trim the logfile

you can get the number of line in line using

# cat file|wc -l

use vi the file and do 1000dd and save the file.

but i would suggest to get the file copied and zip it using

cp -p file file.old
gzip file.old
trim the file
>file

thanks
gany59
Regular Advisor

Re: Trim the logfile

Hi

If i use the sed command

it say as /tmp: write failed, file system is full.. help me !!!!11

Re: Trim the logfile


So try:

# sed -e '1,1000d' filename > /var/tmp/filename.new
# mv /var/tmp/filename.new filename

HTH

Duncan

I am an HPE Employee
Accept or Kudo
Vijaya Kumar_3
Respected Contributor
Solution

Re: Trim the logfile


The sed command stores the output in /tmp file system which is already full. So store the output in a different file system....

sed -e '1,1000d' /tmp/filename > /root/filename.new

Make sute /root/filename.new is corrrect, and then remove the file in the /tmp

rm /tmp/filename

mv /root/filename.new /tmp/filename

Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
Hakki Aydin Ucar
Honored Contributor

Re: Trim the logfile

> Gany: If i use the sed command

it say as /tmp: write failed, file system is full.. help me !!!!11

I am afraid you have reached the %100 in /tmp
if you check you can see:

# bdf /tmp
.. %100 ..

You have got stuck , so you need to delete some files to escape this situation. After you reach under %100 usage of /tmp you can work it.
Fredrik.eriksson
Valued Contributor

Re: Trim the logfile

If you run gnu sed then you can use -i which changes it on the fly (I seem to remember this was is not the case in the HP-UX sed version).

Otherwise, just store the temporary .new file somewhere you have space left.

Best regards
Fredrik Eriksson
Suraj K Sankari
Honored Contributor

Re: Trim the logfile

Hi,
search any core, tar or zip file is there or not in /tmp if found then move some other location or remove the same

#find /tmp -name core -print
#find /tmp -name *.zip -exec ls -l [] \;

what is the log file you found in /tmp please check the time stamp if its old update then take some action remove or move it.

Suraj
gany59
Regular Advisor

Re: Trim the logfile

Hi,

The log file is used by some of the process, so its any possible way to trim the log files , without the kiling the process.
Dennis Handly
Acclaimed Contributor

Re: Trim the logfile

>The log file is used by some of the process, so it's any possible way to trim the log files, without the killing the process.

Probably not. If the process opens, writes and closes, you can. Or opens with append. For the latter, you can't "replace" the file.