Scan your cPanel/Directadmin for excessive files

When dealing with cPanel/Directadmin that contains a lot of users, you need some control of what those users are uploading. Web hosting accounts should be used just for that, hosting websites, and not as data storage – in most cases. Sometimes you even offer packets with unlimited disk capacity but you don’t want that users are storing movies and all kind of other unnecessary files that don’t belong on web hosting account. From web hosting perspective, in most cases, any single file that exceeds 100M is usually not part of website and is just laying there, wasting your precious disk space. In cases like this, account is used as backup service. You’ll be able to find all kind of files. Movies, music, applications, archives …

So you may want to have some reports on regular basis that gives you list of all files that exceed some maximum allowed file size limit – defined by you. Personaly, I scan on interval of 7 days for all files that exceed size of 300M. I created a simple script that will do just that. It will check your /home directory for all files that exceed size that you defined. At the end, report will be sent to your email. You can also scan other directory beside /home if you wish.

Copy script below, create file like /sbin/ and paste its content in it. Of course, you should define variables according to your needs. Don’t forget to give permissions so that script will be able to execute:

chmod +x /sbin/

Add script to your crontab so that it will run on regular interval. In example below, every 10 days.

crontab -e

Than add this line to your cron:

0 0 */10 * * /sbin/ >/dev/null 2>&1

Here is the script:


# global variables

# define your mail

# set file size limit

# hostname of your server

# temp log file

# add header
echo -e "$host - files larger than $limit" >> $temp_file
echo -e "----------------------------------------------------------------------------------------------------\n" >> $temp_file

# send email to address defined below

# send email from - hostname will be used

# define mail subject
mail_subject="Excessive files report - $host"

# directory to scan. You can change if you want. This is default cPanel directory

# search for excessive files
find $path -size +$limit -type f -exec du -h {} \; >> $log_file

if [[ -s "$log_file" ]]; then

       cat $log_file >> $temp_file;
       $MAIL -r $mail_from -s "$mail_subject" $mail_address < $temp_file; else echo "No results" > /dev/null

# remove temp files
rm $log_file
rm $temp_file 

Got Something To Say:

Your email address will not be published.


I accept the Privacy Policy

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2022
Hosted by SIEL

About author