![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Script for automatic deletion of old folder | summerpeh | SUN Solaris | 5 | 09-04-2008 11:27 PM |
| script for deletion using wildcards | aishu | UNIX for Dummies Questions & Answers | 1 | 01-09-2008 05:37 PM |
| Script for automatic deletion of trash file of mail server | crown2100bd | SUN Solaris | 1 | 09-20-2007 09:01 AM |
| Script for automatic deletion of old files | vivek_scv | Shell Programming and Scripting | 4 | 09-09-2007 02:57 AM |
| dynamic global script | isingh786 | Shell Programming and Scripting | 2 | 01-24-2007 08:35 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Dynamic Log Deletion/Rotatoin Script
I've written a small static script for my log deletion, but I was wondering if there was a way to make it a dynamic script. here is how my script currently works. Code:
#!/bin/sh
###########################################
#Script to zip logs older than 1 week old
#and to delete logs older than 30 days old
###########################################
#
##TEST
#
cd /opt/apache/test/logs
find . -name "access_*" -type f -mtime +8 -exec gzip {} \;
find . -name "access_*.gz" -type f -mtime +31 -exec rm {} \;
find . -name "error_*" -type f -mtime +8 -exec gzip {} \;
find . -name "error_*.gz" -type f -mtime +31 -exec rm {} \;
cd /opt/apache/test1/logs
find . -name "access_*" -type f -mtime +8 -exec gzip {} \;
find . -name "access_*.gz" -type f -mtime +31 -exec rm {} \;
find . -name "error_*" -type f -mtime +8 -exec gzip {} \;
find . -name "error_*.gz" -type f -mtime +31 -exec rm {} \;
cd /opt/apache/test2/logs
find . -name "access_*" -type f -mtime +8 -exec gzip {} \;
find . -name "access_*.gz" -type f -mtime +31 -exec rm {} \;
find . -name "error_*" -type f -mtime +8 -exec gzip {} \;
find . -name "error_*.gz" -type f -mtime +31 -exec rm {} \;
echo "Script complete on `date +%D`."
Now for this particular script, i have to simply copy and paste a new block when I create a new apache server, but I figured since the directory structure and log file names are always the same, there would be some way I could add in some actual logic on this. Possibly cd to /opt/apache/, do a listing, then somehow use an array and a loop to capture the name of each directory in to a variable, and then use that variable to run the find command, do those 4 lines, then if another directory exists repeat. |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|