The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Multiple Files deletion in perl pulkit Shell Programming and Scripting 1 02-12-2008 05:55 AM
Finding Hidden files and protecting the folder containing hidden files from deletion pochaw Shell Programming and Scripting 4 12-22-2007 01:33 AM
conditional deletion of log files sonali007 UNIX for Dummies Questions & Answers 3 10-03-2007 11:56 AM
Script for automatic deletion of old files vivek_scv Shell Programming and Scripting 4 09-09-2007 01:57 AM
Regarding deletion of old files Chidvilas Shell Programming and Scripting 3 12-27-2005 10:05 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-20-2006
Geeta Geeta is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 1
Deletion of log files.

We have log files dating back to 2004. I need to write an interative script that will request the user for how many months he needs to keep the log files and remove all the remaing log files after that month.
Supposing we are now in June 2006 , if teh user request to keep log file for the last 3 months, the script will need to delete all the files prior to April 2006. i.e files prior to from April 01 2006 .

Pls suggest a solution

Thanks.
  #2 (permalink)  
Old 06-23-2006
tads98 tads98 is offline
Registered User
  
 

Join Date: May 2005
Posts: 40
The script below will search for files older than $FileAge and compress it. You can change the compress command to delete.

Hope this helps.

#!/bin/ksh
echo "Enter age of file to retain for this compress
echo "1) 1 month 3) 3 months"
echo "2) 2 months 4) Exit"
echo "Please enter your choice : \c"
read choice

case $choice in
1)
echo "compressing all files older than 1 month"
FileAge=30
echo "processing...";;
2)
echo "compressing all files older than 2 months"
FileAge=60
echo "processing...";;
3)
echo "compressing all files older than 3 months"
FileAge=90
echo "processing...";;
4)
echo "You have chosen to exit"
exit;;
*)
echo "Sorry, that's not in the menu.";;
esac

# Compress files that does not end with .Z and .gz from $CompressPath dir
echo "Compressing files from $CurrDir" >&2
for VAR1 in `find "${CompressPath}/." \( ! -name . -a ! -name '*.Z' -a ! -name '*.gz' \) -prune -type f -mountstop -mtime +${FileAge}`
do
# check if an existing compresed name is existing for the target file
if [ -a ${VAR1}.gz ] || [ -a ${VAR1}.Z ]
then
# Append a datestamp to the file
VAR2="${VAR1}.${TimeStamp}"
mv $VAR1 $VAR2

# Proceed to compress this renamed file
#${GZIP} $VAR2
gzip $VAR2
else
#${GZIP} $VAR1
gzip $VAR1
fi
done
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0