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

  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 Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 08-31-2011
Shell_Life's Avatar
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 Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 11:57 AM
need help archive script craig0 Shell Programming and Scripting 7 08-16-2010 05:05 PM
Need some help with an archive script JKMlol Shell Programming and Scripting 7 04-26-2010 11:32 PM
script help .. archive dr46014 Shell Programming and Scripting 1 04-28-2009 10:59 AM
Archive script rauphelhunter Shell Programming and Scripting 1 04-14-2009 09:39 AM



All times are GMT -4. The time now is 12:34 AM.