Skip to content

Instantly share code, notes, and snippets.

@djprmf
Created August 21, 2017 09:56
Show Gist options
  • Select an option

  • Save djprmf/8df9e87ab84700b67b8a66c7fdfe6bd1 to your computer and use it in GitHub Desktop.

Select an option

Save djprmf/8df9e87ab84700b67b8a66c7fdfe6bd1 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Just a quick and simple cpanel cleaning script by @DJ_PRMF
# Homepage: http://tugatech.com.pt and http://djprmf.com
# This script is intended to clean some trash from cpanel servers.
# All the content removed should be safe for standard cpanel installations.
# IM NOT RESPONSIBLE FOR ANY DAMAGE, INCLUDING DATA LOST - except trash -, NUCLEAR WAR OR EXPLOSIONS
# But again, should be safe...
# PLEASE READ - PLEASE READ - PLEASE READ - PLEASE READ - PLEASE READ - PLEASE READ - PLEASE READ - PLEASE READ
# This script is not intended to ALL the servers. This should be used only as a reference.
# Edit the script and comment any command that you don't wanna run in the server.
# In doubt, apply every command manualy and don't run the full script.
# All the archived/compressed logs will be deleted. If you relly in the old logs, make a backup/download them first.
## Shows the usage before cleaning the house
df -h
## Lets clean the YUM
yum clean all
## Remove /var/logs compressed logs and remove any variations (most of the times archived and useless)
rm -f /var/log/*.gz
rm -f /var/log/*.?
rm -f /var/log/archive/*.gz
## Remove /usr/local/apache/logs compressed logs and remove any variations (most of the times archived and useless)
rm -f /usr/local/apache/logs/*.gz
rm -f /usr/local/apache/logs/*.?
rm -f /usr/local/apache/logs/archive/*.gz
## Remove /usr/local/cpanel/logs compressed logs and remove any variations (most of the times archived and useless)
rm -f /usr/local/cpanel/logs/*.gz
rm -f /usr/local/cpanel/logs/*.?
rm -f /usr/local/cpanel/logs/archive/*.gz
## Remove the cloudlinux-collectl archives - If installed under CloudLinux
## Can have a huge ammount of files not needed. Check before delete, if stats are important.
rm -f /var/log/cloudlinux-collect/*.gz
## Now moving on to /home
# Remove all the Core files - Not needed
rm -rf /home/core.*
# Remove Easy Apache update archives - Not needed
rm -rf /home/cpeasyapache
# Remove old MySQL install files
rm -rf /home/MySQL-install
# Remove cPanel File Manager temp files
rm -fv /home/*/tmp/Cpanel_*
# This will clean all the backup files generated under the users accounts.
# Useful if the backup feature in cPanel is enabled and users are not deleting old backups
# Probably you wanna alert the users before, so it will not run by default.
# for user in `/bin/ls -A /var/cpanel/users` ; do rm -fv /home/$user/backup-*$user.tar.gz ; done;
# Remove more useless files in /home
rm -f /home/latest
rm -rf /home/cprubygemsbuild
rm -rf /home/cprubybuild
rm -rf /home/cprestore
#rm -rf /usr/local/cpanel/src/3rdparty/* -> Use with caution. May be needed depending of the server usage. By default not running in the cleaning.
cd /tmp
for files in `ls`; do rm -f $files; done;
# restart MySQL - i leave this off by default, but could be enable to save more space and memory
# /scripts/restartsrv_mysql
# restart Apache (just for a "spring clean)
/scripts/restartsrv_apache
## Output again the space after the cleaning
df -h
## The End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment