TheDude
12-04-2004, 11:20 PM
This script cleans any file in any directory
#!/bin/bash
################################################## #############################
#
# @(#) Script : clean.sh
# @(#) ID Num :
# @(#) Syntax : clean
# @(#) Function : Daily deletion of old backup files.
# @(#) Description :
#
# @(#) Written : December 4, 2004
# @(#) Author : Onling.com
# @(#)
#
################################################## #############################
#
# Revision History :
# @(#) Date By Revision Desciption
# @(#) -------- ------------------- ---------------------------------------
# @(#)
#
################################################## #############################
#
# Onling.com
# All Rights Reserved.
#
# GNU License
# The information in this file is provided "AS IS" without warranty.
#
################################################## #############################
#
# Step 1: Setup time variable
# Check SCO or HP-UX / AIX
#
actime="mtime" # Linux
uname -X 1>/dev/null 2>&1 ; SCO_=$? # Test for SCO with uname -X
[ ${SCO_} = "0" ] && actime="ctime" # SCO
#
################################################## #############################
#
# Step 2: Set the directories to start from
# You can setup multipules of the variables
#
$BACKUPS = /u2/back/
#
################################################## #############################
#
# Step 3: The following is looking for files 24 Hours ago and less
#
# -$actime +0 is 24hours from the time the script runs
# -$actime +1 is 48 hours and +2 is 60 hours and ect..
# You can add many file types like below
# -name "filename.ext" -o -name "filename.ext"
#
find $BACKUPS \( -name "*.TM" -o -name "*.LS" \) -${actime} +0 -exec rm -f {} \;
#
#
################################################## #############################
#
# Step 4: Remove
#
# You can do ranges like below with the Filename[0-9].Log
#
find $BACKUPS \( -name "Backup[0-9]*.Log" \) -${actime} +6 -exec rm -f {} \;
#
#
################################################## #############################
#
# Step 5: Remove
#
# This is just plan ole delete them all
#
find $BACKUPS \( -name "SQ*.LOG"\) -exec rm -f {} \;
#
#
################################################## #############################
#
# Step 6: Remove
#
# This is to remove by size in the start directory
#
find $BACKUPS \(-name "*" \) -size 0 -exec rm -f {} \;
#
#
################################################## #############################
#
# Step 7: Remove old mail files. Use id to check for superuser.
#
if [ `id | cut -d"=" -f2 | cut -d"(" -f1` -eq 0 ]; then
find /usr/spool/mail -type f -${actime} +30 -exec rm -f {} \;
fi
#
#
################################################## #############################
#
# Step 8: Remove
#
# Remove all with directory specified
#
find /u/whatever/whereever/ -mtime +30 -exec rm -f {} \;
#
#
################################################## #############################
exit 0
Enjoy!!!
#!/bin/bash
################################################## #############################
#
# @(#) Script : clean.sh
# @(#) ID Num :
# @(#) Syntax : clean
# @(#) Function : Daily deletion of old backup files.
# @(#) Description :
#
# @(#) Written : December 4, 2004
# @(#) Author : Onling.com
# @(#)
#
################################################## #############################
#
# Revision History :
# @(#) Date By Revision Desciption
# @(#) -------- ------------------- ---------------------------------------
# @(#)
#
################################################## #############################
#
# Onling.com
# All Rights Reserved.
#
# GNU License
# The information in this file is provided "AS IS" without warranty.
#
################################################## #############################
#
# Step 1: Setup time variable
# Check SCO or HP-UX / AIX
#
actime="mtime" # Linux
uname -X 1>/dev/null 2>&1 ; SCO_=$? # Test for SCO with uname -X
[ ${SCO_} = "0" ] && actime="ctime" # SCO
#
################################################## #############################
#
# Step 2: Set the directories to start from
# You can setup multipules of the variables
#
$BACKUPS = /u2/back/
#
################################################## #############################
#
# Step 3: The following is looking for files 24 Hours ago and less
#
# -$actime +0 is 24hours from the time the script runs
# -$actime +1 is 48 hours and +2 is 60 hours and ect..
# You can add many file types like below
# -name "filename.ext" -o -name "filename.ext"
#
find $BACKUPS \( -name "*.TM" -o -name "*.LS" \) -${actime} +0 -exec rm -f {} \;
#
#
################################################## #############################
#
# Step 4: Remove
#
# You can do ranges like below with the Filename[0-9].Log
#
find $BACKUPS \( -name "Backup[0-9]*.Log" \) -${actime} +6 -exec rm -f {} \;
#
#
################################################## #############################
#
# Step 5: Remove
#
# This is just plan ole delete them all
#
find $BACKUPS \( -name "SQ*.LOG"\) -exec rm -f {} \;
#
#
################################################## #############################
#
# Step 6: Remove
#
# This is to remove by size in the start directory
#
find $BACKUPS \(-name "*" \) -size 0 -exec rm -f {} \;
#
#
################################################## #############################
#
# Step 7: Remove old mail files. Use id to check for superuser.
#
if [ `id | cut -d"=" -f2 | cut -d"(" -f1` -eq 0 ]; then
find /usr/spool/mail -type f -${actime} +30 -exec rm -f {} \;
fi
#
#
################################################## #############################
#
# Step 8: Remove
#
# Remove all with directory specified
#
find /u/whatever/whereever/ -mtime +30 -exec rm -f {} \;
#
#
################################################## #############################
exit 0
Enjoy!!!