Logfile Size exceeded ????


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Logfile Size exceeded ????
# 1  
Old 01-18-2008
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
# 2  
Old 01-18-2008
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
# 3  
Old 01-18-2008
ThanQ Franklin !!!

Quote:
Originally Posted by Franklin52
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
# 4  
Old 01-18-2008
Bug 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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Logfile monitoring with logfile replacement

Bonjour, I've wrote a script to monitor a logfile in realtime. It is working almost perfeclty except for two things. The script use the following technique : tail -fn0 $logfile | \ while read line ; do ... some stuff done First one, I'd like a way to end the monitoring script if a... (3 Replies)
Discussion started by: Warluck
3 Replies

2. Emergency UNIX and Linux Support

Disk quota exceeded (difference btw. du and df, again!)

I haven't been able to do anything since yesterday evening because my account is full to the brim. Very annoying on a Friday evening when no admin will be in until Monday morning. Of course, I might consider cleaning up if I knew where the problem is, but I can't figure it out because du and df... (8 Replies)
Discussion started by: mregine
8 Replies

3. Shell Programming and Scripting

Problem with awk awk: program limit exceeded: sprintf buffer size=1020

Hi I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it The code is that: { if (NF==17){ print $0 }else{ fields=NF; all=$0; while... (2 Replies)
Discussion started by: fate
2 Replies

4. Shell Programming and Scripting

[sh] While loop -> Expression recursion level exceeded

Hi! I wanted to use a while loop, like the one below, for checking words extracted by awk to terminate when a specific word appears. Unfortunately whenever I put my code inside the loop I get an error "Expression recursion level exceeded". What does it mean? What recursion? I don't have any... (4 Replies)
Discussion started by: machinogodzilla
4 Replies

5. UNIX for Dummies Questions & Answers

Disk quota exceeded......

I keep on getting an error on my site saying I've got a 250GB dedicated server, and have used less than 200mb of that. The site has only been on the server for just over a month. What does this mean and how can I sort it? (8 Replies)
Discussion started by: thehaapyappy
8 Replies

6. UNIX for Dummies Questions & Answers

File size limit exceeded... SCO ulimit?

Hello - O/S is UnixWare 7.1.4 My prefered method of copying files between servers is 'rcp', which does not recognize symbolic links; therefore, files are duplicated many times over. To avoid this duplication, I would like to use 'tar' and/or 'cpio' and pipe them through 'rcp', but... (1 Reply)
Discussion started by: rm -r *
1 Replies

7. HP-UX

Count Exceeded Error on HP-UNIX

Sirs/Madame, On my HP-Unix, I came across an error GRECV-count exceeded and as a result of this, systems got hanged and server came down. Graceful shutdown too was not allowed. Kindly, Can anybody help me out in killing this issue Bhavani.R (0 Replies)
Discussion started by: bhavani2006
0 Replies

8. Programming

File size limit exceeded

When i run my C program which dynamically creates the output file, the program stops after sometime and gives the error "File size limit exceeded" even though my working directory has space.Can anyone plz help me out. (13 Replies)
Discussion started by: drshah
13 Replies

9. UNIX for Dummies Questions & Answers

SCO Openserver 5.0.7 NSTRPAGES Exceeded

Hello guys i'm getting this error on a sco 5.0.7 machine and i have no idea why i'm getting this error. I know how to encrease the value of NSTRPAGES, right now i have it up to 4000. I would like to know what is NSTRPAGES and what is causing this error to come up in my server. Thanks a... (2 Replies)
Discussion started by: josramon
2 Replies

10. Shell Programming and Scripting

check logfile size

Hello everyone! Can anyone help me with this? I need a script that looks at a logfile and check itīs size. If itīs over a sertain size the i should get an email. Dont really know how the grep that info "the size" Please help.... (4 Replies)
Discussion started by: dozy
4 Replies
Login or Register to Ask a Question