Log archive script | Unix Linux Forums | Shell Programming and Scripting

  Unix/Linux Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Log archive script

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 08-31-2011
gubbu gubbu is offline
Registered User
 
Join Date: Mar 2009
Last Activity: 21 March 2014, 12:39 AM EDT
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Log archive script

I need a log archival script which will delete files older than 3 days in a given JBOSS log directory which has files as follows
server.log.2011-08-25
server.log.2011-08-26
server.log.2011-08-27
server.log.2011-08-28
server.log

I only want to save server.log and 3 days before server.log and delete rest of the files since I store everything to Splunk.
Sponsored Links
    #2  
Old Unix and Linux 08-31-2011
Shell_Life's Unix or Linux Image
Shell_Life Shell_Life is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 21 June 2012, 3:19 PM EDT
Location: Bahia, Brazil
Posts: 1,203
Thanks: 1
Thanked 103 Times in 100 Posts
Here is one way of doing it:

Code:
#!/usr/bin/ksh
for mFName in $(ls -1 server.log* | sort | sed '1,4d'); do
  echo "Now deleting <${mFName}>"
  rm -f ${mFName}
done

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Archive script deva78 Shell Programming and Scripting 3 06-03-2011 12:57 PM
need help archive script craig0 Shell Programming and Scripting 7 08-16-2010 06:05 PM
Need some help with an archive script JKMlol Shell Programming and Scripting 7 04-27-2010 12:32 AM
script help .. archive dr46014 Shell Programming and Scripting 1 04-28-2009 11:59 AM
Archive script rauphelhunter Shell Programming and Scripting 1 04-14-2009 10:39 AM



All times are GMT -4. The time now is 08:04 PM.