The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" iBot UNIX and Linux RSS News 0 01-04-2008 11:00 AM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-19-2007 09:52 PM
check input = "empty" and "numeric" geoffry Shell Programming and Scripting 6 12-13-2007 01:12 AM
Command similar to "touch" for modify File size sriharshareddyk UNIX for Advanced & Expert Users 3 11-14-2007 09:43 PM
Maximum input file size in "Diff" Command Neeraja UNIX for Dummies Questions & Answers 1 01-17-2007 06:09 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-13-2007
Registered User
 

Join Date: Nov 2007
Posts: 18
Stumble this Post!
"sed" to check file size & echo " " to destination file

Hi,

I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set back to zero.
If somebody can help me with a sed command to check the size of messages & to do a echo "" > messages ,if the size is greater than 128KB, I'll really grateful.

Wishes
Jay

Last edited by jockey007; 11-13-2007 at 11:47 AM. Reason: typo
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 11-13-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Stumble this Post!
You could actually use find!

Code:
find /var/log -name messages -type f -size +131072c
Reply With Quote
  #3 (permalink)  
Old 11-13-2007
Registered User
 

Join Date: Nov 2007
Posts: 18
Stumble this Post!
Thanks....

Now I'm using a busybox find, which doesn't have support for "-size" argument
So i think a sed command that meets the requirement would be great.
Please provide a sed command to check the file & then flush that file.

Wishes
Jay
Reply With Quote
  #4 (permalink)  
Old 11-13-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Stumble this Post!
Then it would help to know how you intend to use sed.

What does the output from "ls -ld /var/log/messages" look like?
Reply With Quote
  #5 (permalink)  
Old 11-13-2007
Registered User
 

Join Date: Nov 2007
Posts: 18
Stumble this Post!
Hi Porter,

The output of
root@WiMAX-BS:/var/log ls -ld /var/log/messages
-rw------- 1 root root 41994 Jan 23 03:16 /var/log/messages

==========

Well.. I was thinking like
1) use the ls command grab the size value using the sed and
2) then if it is greater than 128KB, do an echo " " > /var/log/messages

Now I've crond support, so I can add a script with above logic to cron job.

Thanks
Jay
Reply With Quote
  #6 (permalink)  
Old 11-13-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Stumble this Post!
Code:
#!/bin/sh

LOG=/var/log/messages

fifth()
{
     echo $5
}

SIZE=`ls -ld $LOG`
SIZE=`fifth $SIZE`

if test "$SIZE" -gt 131072
then
      date >$LOG
fi
Reply With Quote
  #7 (permalink)  
Old 11-13-2007
Registered User
 

Join Date: Nov 2007
Posts: 18
Stumble this Post!
Thumbs up

Oh!! That works!

Thanks a lot Porter...
Have a nice day.

Wishes
Jay

Last edited by jockey007; 11-13-2007 at 05:10 PM.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:59 PM.


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

Content Relevant URLs by vBSEO 3.2.0