Sponsored Content
Top Forums Shell Programming and Scripting Remove excess log files past data mark Post 302912744 by Samuel12 on Monday 11th of August 2014 04:14:34 PM
Old 08-11-2014
Remove excess log files past data mark

I have got application log files collecting up fast inside of a directory.

The logs contains many logs that look like this (were talking 1000s+):
the Log_NAME followed by Date and application specific nonsense.

Code:
(...)
application_log_2014-07-13_20-30-09 
application_log_2014-07-20_08-30-27 
(...)

Below is an excerpt of a script I use to backup excess log files before I remove all, I was wondering if anyone had any idea how I could create a script within this where I remove all scripts for last month. I think it should be possible to safely remove all the: application_log_*.... that are say older then $DT_limit I set. However I need expert opinion on this because I can not exceed the limit I set and need to be safe as folder contains other .ini and log files that must be ignored so care is needed.

Code:
##LOG FILE LOCATIONS##
##LOG FILE LOCATIONS##
##LOG FILE LOCATIONS##
export EXCESS_LOG_LOCATION="/excess_log/location"
export BACKUPDIR="/backup/log_backup"
export LOGFILE_LOCATION="/log_location"
 
## Date/Time variables

DT=`date '+%F:%H:%M'`


for file in `ls $EXCESS_LOG_LOCATION/application_log_*`
do
  mv ${file} ${BACKUPDIR}
  echo "log processed file ${file}" >> ${LOGFILE_LOCATION}
done
 
exit 0

I will post a script I am thinking of using as soon as I make progress but if anyone has an idea or has done this before let me know.


FYI - Ignore the Backup AND MV command functionality please this is just to help you see the logic I want to follow. and help you understand where I am trying to place the date check*.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to remove log files

Can anyone help me with a shell script to remove all files (log files) created 7 days before current system date. TIA, Kiran. (1 Reply)
Discussion started by: kiranherekar
1 Replies

2. Shell Programming and Scripting

shell script for log files data!

Hi Team, please write a shell script. It is for veritas netbackup logs. The result we currently have is a single file for each day's backups. we will keep the files in the directory and the file names are like below mentioned. example :/opt/openv/netbackup/reports/Daily/NB_success*. The No... (6 Replies)
Discussion started by: rvrao77
6 Replies

3. Solaris

Find 3 months old log files and remove

HI I HAVE LOG FILES IN THIS FORMAT XXX.log.20080509215745 XXX.log.20080209205745 XXX.log.20080301785745 XXX.log.20080109155745 XXX.log.20080409115745 XXX.log.20080309105745 I NEED TO FIND THE FILES FROM 3 MONTHS OLD AND REMOVE PLEASE HELP THANKS, (13 Replies)
Discussion started by: cvdev
13 Replies

4. Shell Programming and Scripting

find files from the past 7 days

Hi All, I have a file which contains the listing of another directory: >cat list.dat -rwxr-xr-x 1 test staff 10240 Oct 02 06:53 test.txtdd -rwxrwxrwx 1 test staff 0 Oct 04 07:22 test.txx -rwxrwxrwx 1 test staff 132 Sep 16 2007 test_tt.sh... (6 Replies)
Discussion started by: deepakgang
6 Replies

5. Shell Programming and Scripting

shell script to remove old files and write to a log file

Hi, I have a script that works on a unix box but am trying to get it working on a linux box that uses shell. I am not a programmer so this is proving harder than I imagined. I made some changes and ended up with the script below but when I run it I get the following messages. Any help would be... (4 Replies)
Discussion started by: yabai
4 Replies

6. Shell Programming and Scripting

Modify log files to get uniq data

Hello, I have a log file that has following output as below. LAP.sun5 CC LAP.sun5 CQ perl.sun5 CC perl.sun5 CQ TSLogger.sun5 CC TSLogger.sun5 CQ TSLogger.sun5 KR WAS.sun5 CC WAS.sun5 MT WAS.sun5 CQ I want to output to be in the way below, i tried using awk but could not do it. ... (12 Replies)
Discussion started by: asirohi
12 Replies

7. Shell Programming and Scripting

Listing files of PAST 7 days and concatenate it...

Hi All, I want to list file of LAST 7 days acc. to its modified date and then concatinate. I have following piece of code.. For concatenate cat file1 file2 >> Output (For concatinating) find . -mtime -7 -exec basename {} \; (list past files but it is including . file also) Plz... (4 Replies)
Discussion started by: vivek1489
4 Replies

8. Shell Programming and Scripting

Can you extract (remove) lines from log files?

I use "MineOS" (a linux distro with python scripts and web ui included for managing a Minecraft Server). The author of the scripts is currently having a problem with the Minecraft server log file being spammed with certain entries. He's working on clearing up the spam. But in the meantime, I'm... (8 Replies)
Discussion started by: nbsparks
8 Replies

9. UNIX for Dummies Questions & Answers

Find command to get the modified files past 2 hours

Hello, How to get the modified/created files past 2 hours in Solaris with find command? Thank you. (7 Replies)
Discussion started by: balareddy
7 Replies

10. Shell Programming and Scripting

How to select all files added to a directory in the past 5 mins (HP-UX)?

Hey everyone, I need to select all files that were added to a specific directory in the past 5 mins and copy them over to a different directory. I am using HP-UX OS which does not have support for amin, cmin, and mmin. B/c of this, I am creating a temp file and will use the find -newer command... (7 Replies)
Discussion started by: mattkoz
7 Replies
SCANLOGS(8)						      System Manager's Manual						       SCANLOGS(8)

NAME
scanlogs - summarize INN log files. SYNOPSIS
scanlogs [ norotate ] [ nonn ] DESCRIPTION
Scanlogs summarizes the information recorded in the INN log files (see newslog(5)). By default, it also rotates and cleans out the logs. It is normally invoked by the news.daily(8) script. KEYWORDS
The following keywords are accepted: norotate Using this keyword disables the rotating and cleaning aspect of the log processing: the logs files are only scanned for information and no contents are altered. nonn Normally the nn log file is scanned and rotated. Using this keyword disables this function. If scanlogs is invoked more than once a day, the ``norotate'' keyword should be used to prevent premature log cleaning. HISTORY
Written by Landon Curt Noll <chongo@toad.com> and Rich $alz <rsalz@uunet.uu.net> for InterNetNews. This is revision 1.1, dated 1996/10/29. SEE ALSO
innd(8) newslog(5), news.daily(8), nnrpd(8). SCANLOGS(8)
All times are GMT -4. The time now is 03:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy