Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 02-18-2005, 04:56 PM   #1
LQ Newbie
Registered: Feb 2005
Location: USA
Posts: 16

Rep: Reputation: 0
trying to remove a defined # of logs

I am trying to automate my log handling for several scripts that are running. And the worst thing is a I am newbie as you can see by the script.

I want to retain 3 days worth of logs, anything greater then 3 I want delete.

is there a way I can do this?


DATE=`eval date +%m%d%y`
# logs are formatted as: $SUFFIX-*-backup.log
logcount=`ls *-*error.log |wc -l`

#for this test I only want to keep 3 historical logs
until [ $logcount -lt 3 ]; do
logcount=$(($logcount - 1))
SUFFIX=$(($SUFFIX - 000300))
echo "Removing "$DATE".log"
rm -R $SUFFIX*.log

getting error on:
SUFFIX=$(($SUFFIX - 000300))

And I am stumped... any suggestion / hints / etc.. would be greatly appreciated. Back to
Old 02-18-2005, 09:49 PM   #2
Registered: Jun 2003
Location: Virginia, USA
Distribution: Slackware
Posts: 252

Rep: Reputation: 30
look an man logrotate, this is a nice tool that does exactly what you are looking for.

Old 02-21-2005, 10:13 AM   #3
LQ Newbie
Registered: Feb 2005
Location: USA
Posts: 16

Original Poster
Rep: Reputation: 0
thank you. I will look into it.


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
Firewall logs in logs and terminal... robbow52 Debian 7 11-20-2004 07:13 PM
Firefox logs user out? Where are error logs? case1984 Linux - General 0 10-09-2004 02:22 PM
Separate firewall logs and general logs dominant Linux - General 3 04-20-2004 01:26 AM
/var/logs = 11gigs!!! Safe to remove? breakerfall Linux - General 17 02-18-2004 04:59 PM
Apache logs - ???Linux logs??? mylo2003 Linux - General 3 08-07-2003 04:49 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:46 AM.

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