delete first 100 lines rather than zero out of file

Hi experts,

in my solaris 9 the file- /var/adm/messeages growin too first. by 24 hours 40MB. And always giving the below messages--

bash-2.05# tail -f messages
Nov 9 16:35:38 ME1 last message repeated 1 time
Nov 9 16:35:38 ME1 ftpd[16392]: [ID 476795 daemon.error] wtmpx /var/adm/wtmpx No such file or directory
Nov 9 16:35:38 ME1 last message repeated 1 time
Nov 9 16:35:38 ME1 ftpd[16393]: [ID 476795 daemon.error] wtmpx /var/adm/wtmpx No such file or directory
Nov 9 16:35:38 MEMM1 last message repeated 1 time
---
i then tried with #touch wtmpx. Although the above messages stops but wtmpx grows more faster than file 'messages'. so i again delete 'wtmpx'. For your information this SUN server uses for various types of FTP everyminutes. So, far i know 'wtmpx' files logs the user access. that is why it grows too fast.
I now plan to adjust a script in crontab which will delete first 100 lines from messages after 2/3 days.
But i don't know how to implement the script. Could anyone help me??

Cheers
purple

The following command will delete the first 100 lines from your wtmpx file:

$ sed '1,100d' wtmpx

However, if your wtmpx file grows by 40MB's every 24 hours I reckon 100 lines will not make much of a difference. Do a cat wtmpx |wc -l to count the lines and then decide how many lines you should delete to shrink the file size sufficiently.

Hi soliberus,
I tried to delete first 100 lines of file messages with command # sed '1,100d' messages. But it is not working. Please see below.
bash-2.05# cat messages |wc -l
36948
bash-2.05# sed '1,100d' messages
bash-2.05# cat messages |wc -l
36949
bash-2.05#

And about 'wtmpx'- the file is not understanble to me :(. So, i plan to delete only lines from 'messages'
bash-2.05# tail -f wtmpx
bgwftpftp10010'G4)192.168.210.35bgwftpftp10010G4)192.168.210.35bgwftpftp10012'G4)192.168.210.35bgwftpftp10011'4)192.168.210.42bgwftpftp10012G4)192.168.210.35bgwftpftp100114)192.168.210.42bgwftpftp10013'G4*192.168.210.35bgwftpftp10013G4*192.168.210.35bgwftpftp10014'G4+192.168.210.42bgwftpftp10014G4+192.168.210.42bgwftpftp10015'G4+192.168.210.37bgwftpftp10015G4+192.168.210.37bgwftpftp10016' G4+192.168.210.40bgwftpftp10016'G4+192.168.210.40bgwftpftp10017'!G4+192.168.210
bash-2.05# cat wtmpx |wc -l
13
Though it shows only 13 lines and lines are growing slowly but File size is growing to much fast.

Ooops, I didn't give you the full script.

It should look something like this:

sed '1,100d' messages > messages.tmp
cat messages.tmp > messages
rm message.tmp

I'm sure this is not the most effective way of truncating a file, but it works.

Hi buddy, many thanks for the script. It should work.

if ' -i ' option is available in the sed you are using ( GNU sed )

use it

sed -i '1,100d' file

just the above would do

Hi all, i told you i m getting mainly prob with frequently growing 2 files /var/adm/messages OR /var/adm/wtmpx.
I got a solution for overgrowing wtmpx. Below is the line need to put in cronjob. it will empty wtmpx file after every 30 minutes.

30 * * * * su - root -c "cat /dev/null > /var/adm/wtmpx" > /dev/null 2>&1

I get it from sun solaris 8. Although i am using solaris 9 but hope line should work it also . However, can anyone tell me what is the value here "root -c" and "2>&1"??

-c ==> pass a single command to the shell

2 > &1 ==> redirect the output of stderr where output of stdout has been redirected