LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-04-2001, 04:40 PM   #1
drobson
LQ Newbie
 
Registered: May 2001
Distribution: RedHat 7.1
Posts: 17

Rep: Reputation: 0

I want a script that will allow me to either completely
empty the contents of
various log files or perhaps save only the previous days entries and erase all older entries.
I thought I remember reading having to do something about the various demons that wrote to those log files before you
could operate on them,
but I can't remember where I might have read it, nor can I remember the details.
I know experienced sysadmins do this kind of thing all the time in cron, but I'm a newbie just learning, so help would
be much appreciated.

Doug Robson
drobson@chartertn.net
 
Old 06-04-2001, 07:44 PM   #2
aimstr8
Member
 
Registered: Mar 2001
Posts: 40

Rep: Reputation: 15
Doug,

First read the man page on logrotate.

I am not much of a programer, but the below script is a hack at doing what it sounds like you want. Just change it to suit your needs and put it in a cront job.


--------------------------------START HERE-----------------------------------
!/bin/ksh
#
#set defaults
# Set date & time stamp

date=`date|cut -c5-11,25-|sed 's/\([0-9]\{1,2\}\)/\1,/'`
time=`date +"%D"|sed 's/0//'`
time2=`date +%d/%b/%Y`
#
cat /var/log/messages|grep INVADING|grep "$time"> /var/log/test.log
cat /var/log/httpd/access_log|grep "$time2">> /var/log/test.log
#
#
# Control File Size
#
big=`ls -l /var/log/test.log |awk '{print $5}'`

if [ "$big" -gt 600 ]
then
echo "test log is $big in size as of `date +"%D %T"`" | mail -s "Test HTML log File `date +"%D %T"`" root

tar cfz /var/log/test.log.tar.gz /var/log/test.log
sleep 2
mv /var/log/test.log.tar.gz /var/log/test.log.tar.gz.`date +%Y.%m.%d`
sleep 2
#mv /var/log/test.log.tar.gz* /var/log/OLD/
ls -lh /var/log/test* | mail -s "Test HTML log File `date +"%D %T"`" root
#ls -lh /var/log/OLD/test*| mail -s "Test HTML log File `date +"%D %T"`" root

else
echo "Test HTML log file is good at $big"| mail -s "Test HTML log File is good at $big on `date +"%D %T"`" root
fi
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache logs empty nikonos Linux - Newbie 3 04-26-2014 03:09 PM
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
Bash Script test for empty dir uopjohnson Linux - Software 3 10-07-2005 06:45 PM
How can I check wether a file is empty in Linux by using shell script programming ??? Bassam Linux - General 2 02-26-2004 01:01 AM
apache is writing empty logs ocularbob Linux - Software 1 07-03-2003 02:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration