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
Disk quota exceeded...... thehaapyappy UNIX for Dummies Questions & Answers 8 05-13-2008 10:07 AM
File size limit exceeded... SCO ulimit? rm -r * UNIX for Dummies Questions & Answers 1 10-22-2007 02:52 PM
File size limit exceeded drshah High Level Programming 13 03-02-2006 11:11 PM
SCO Openserver 5.0.7 NSTRPAGES Exceeded josramon UNIX for Dummies Questions & Answers 2 08-02-2005 12:29 PM
check logfile size dozy Shell Programming and Scripting 4 05-27-2003 03:26 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-18-2008
Registered User
 

Join Date: Jun 2007
Posts: 115
Logfile Size exceeded ????

Hi,

How to write a script which checks the size of a log file?
I want that the log file contents to get cleared as soon as it increases 1 KB.

Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 01-18-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,329
You can do something like:

Code:
#!/bin/ksh

used=`du -b logfile|awk '{print $1}'`
if [ "$used" -gt 1024 ]; then
  # do your stuff here
fi
Regards
Reply With Quote
  #3  
Old 01-18-2008
Registered User
 

Join Date: Jun 2007
Posts: 115
ThanQ Franklin !!!

Quote:
Originally Posted by Franklin52 View Post
You can do something like:

Code:
#!/bin/ksh

used=`du -b logfile|awk '{print $1}'`
if [ "$used" -gt 1024 ]; then
  # do your stuff here
fi
Regards
Reply With Quote
  #4  
Old 01-18-2008
Registered User
 

Join Date: Jan 2008
Posts: 12
Smile My first contribution ...to this forum

#! /usr/bin/ksh

interval=900 ## check for logfile size once in this much seconds

while true ; do
size_of_file=`ls -l logfile | awk '{ print $5}'`

if [ ${size_of_file} -ge 1024 ]
then
datestamp=`date "+%m%h%Y_%H%M%S"
cp logfile /archive/logfile.${datestamp} ## take an archive
cp /dev/null logfile
fi
sleep $interval

done
Reply With Quote
Google The UNIX and Linux Forums
Reply

« sed help. | egrep »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:43 AM.


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