Bash Script To Find and Delete All Files Except Some When the filesystem reaches a specific size

#!/bin/sh

# This script checks if the /siebel filesystem reaches the warning limit of free space
# And then delete the old logs except those of last 12 hours

warninglimit=1572864    # This number is in KB, it’s equal to 1.5 GB,
                        # KB is used to avoid floating point numbers

filesystem=”/siebel”   # The filesystem to be monitored

size=`df -k $filesystem|grep $filesystem|awk ‘{ print $3; }’`   # Extract size of /siebel Filesystem in KB

if [ $size -le $warninglimit ]  # If fs size is less than warning lim.
    then
              find /siebel/siebsrvr/enterprises/ESPRD/$HOSTNAME/log -cmin +720 \( ! -name “ESPRD*” \) | xargs rm  # Delete log files that are more than 12 hours old from now (except those starting with “ESPRD”)
fi

Credit goes to Osama Magdy for the above script.

About SoCRaT

Systems Engineer, OSS & Linux Geek
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s