Bigfile checker

This short script checks for files greater than 200Mb which may be queued for deletion. The results are mailed to the $MAILLIST variable. The script is best cron-ed to run once per week.

Some files can be ignored by this script. Database data files (with a *.d extension) of other files ending in b[0-9] extensions may be supposed to be large and would therefore be false positives. More such filetypes can be added to the find command by adding more parameters to the

\( -name "*.d*" -o -name "*.b[0-9]" \)

construct. For example, to ignore *.txt files, use

\( -name "*.d*" -o -name "*.b[0-9]" -o "*.txt" \)

bigfilecheck script

#!/bin/sh
DIRS="/dir1 /dir2 /dir3 /dir4"
BIGLIST=/tmp/bigfiles.$$
MAILLIST=sysop@example.co.uk
find $DIRS ! \( -name "*.d*" -o -name "*.b[0-9]" \) -size +210000000c -exec ls -lh {} \; >> $BIGLIST


(cat << EOF

Current disk usage on `hostname` is

`df -hl`

The following files with size greater than 200Mb have been found under $DIRS .

`cat $BIGLIST`

Please investigate ASAP.

EOF
) | mailx -s "`hostname` big files alert" $MAILLIST -- -f root@example.co.uk

# Clean up the temp file
if [ -f $BIGLIST ]; then
    rm $BIGLIST
fi