The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > SUN Solaris
Google UNIX.COM


SUN Solaris The Solaris Operating System, usually known simply as Solaris, is a free Unix-based operating system introduced by Sun Microsystems .

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
delete n last lines of a file ncatdesigner Shell Programming and Scripting 7 05-17-2008 07:07 AM
delete first 100 lines from a file salaathi SUN Solaris 3 11-15-2007 01:01 AM
delete the lines from file sameersam Shell Programming and Scripting 2 04-03-2006 10:32 PM
Delete lines in a file umal Shell Programming and Scripting 6 02-08-2006 10:08 AM
delete all lines in file strok UNIX for Dummies Questions & Answers 6 03-11-2002 07:27 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-09-2007
Registered User
 

Join Date: Oct 2007
Posts: 68
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
Reply With Quote
Forum Sponsor
  #2  
Old 11-09-2007
Registered User
 

Join Date: Oct 2004
Posts: 73
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.
Reply With Quote
  #3  
Old 11-09-2007
Registered User
 

Join Date: Oct 2007
Posts: 68
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.35bgwft pftp10011'4)192.168.210.42bgwftpftp10012G4)192.168.210.35bgwftpftp100114)192.168.210.42bgwftpftp1001 3'G4*192.168.210.35bgwftpftp10013G4*192.168.210.35bgwftpftp10014'G4+192.168.210.42bgwftpftp10014G4+1 92.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.
Reply With Quote
  #4  
Old 11-12-2007
Registered User
 

Join Date: Oct 2004
Posts: 73
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.
Reply With Quote
  #5  
Old 11-13-2007
Registered User
 

Join Date: Oct 2007
Posts: 68
Quote:
Originally Posted by soliberus View Post

It should look something like this:

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

Hi buddy, many thanks for the script. It should work.
Reply With Quote
  #6  
Old 11-13-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
if ' -i ' option is available in the sed you are using ( GNU sed )

use it

Code:
sed -i '1,100d' file
just the above would do
Reply With Quote
  #7  
Old 11-14-2007
Registered User
 

Join Date: Oct 2007
Posts: 68
delete first 100 lines rather than zero out of file

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"??

Quote:
Originally Posted by thepurple View Post
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.35bgwft pftp10011'4)192.168.210.42bgwftpftp10012G4)192.168.210.35bgwftpftp100114)192.168.210.42bgwftpftp1001 3'G4*192.168.210.35bgwftpftp10013G4*192.168.210.35bgwftpftp10014'G4+192.168.210.42bgwftpftp10014G4+1 92.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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:36 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0