![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|