The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 03:00 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM
check input = "empty" and "numeric" geoffry Shell Programming and Scripting 6 12-13-2007 05:12 AM
Command similar to "touch" for modify File size sriharshareddyk UNIX for Advanced & Expert Users 3 11-15-2007 01:43 AM
Maximum input file size in "Diff" Command Neeraja UNIX for Dummies Questions & Answers 1 01-17-2007 10:09 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-13-2007
jockey007 jockey007 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 18
"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 03:47 PM.. Reason: typo
  #2 (permalink)  
Old 11-13-2007
porter porter is offline Forum Advisor  
Registered User
  
 

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

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

Join Date: Nov 2007
Posts: 18
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
  #4 (permalink)  
Old 11-13-2007
porter porter is offline Forum Advisor  
Registered User
  
 

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

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

Join Date: Nov 2007
Posts: 18
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
  #6 (permalink)  
Old 11-13-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
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
  #7 (permalink)  
Old 11-13-2007
jockey007 jockey007 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 18
Thumbs up

Oh!! That works!

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

Wishes
Jay

Last edited by jockey007; 11-13-2007 at 09:10 PM..
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0