[GUIDE] Logs Cleaner for CyberPanel

I recently had a serious problem with the logs, the switchLSWSStatus file weighed over 700GB. Therefore I decided to share my script with you to always keep the server logs clean.


sudo -i
cd /root/
nano logscleaner.sh

Paste this code:

# Software Logs Cleaner v1.0alpha, use only for test
# Powered by Nicholas Sciortino

# clear all logs of CP
rm -rf /usr/local/lsws/logs/*

# clear OpenLiteSpeed cache folder
rm -rf /usr/local/lsws/cachedata

# remove old CyberPanel versions
rm -rf /usr/local/*.tar.gz

# clear other logs
rm -f /home/cyberpanel/switchLSWSStatus
rm -f /home/cyberpanel/stderr.log
rm -f /home/cyberpanel/error-logs.txt

After you have to give permissions to the executable file

chmod +x logscleaner.sh

Now you can run it manually with the command, after you have cleared all logs and freed up a lot of memory ^^

sh logscleaner.sh

We can also automate cleanup using a cron

crontab -e

At the end of the file add

0 0 * * 0 sh /root/logscleaner.sh

Once a week the script will be executed which will delete all the logs


I’ve had no problem with the LS logs. Ours was miniscule

However, we did have some big problems with space. We maxed it out.
I did a lot of digging and was able to track it back to the Linux logs, some old staging sites, some trash bins not cleaned out, and some old .sql and .gz files sitting

I was able to clean out about 7 GB of space by doing all that (My journal files were 1.4 GB).

I wrote this script in response. It cleans up the journal and then looks through and suggests other places that might be problematic.

Mind you this does use sudo on each folder so some might find that problematic. I may try updating and seeing if I can iterate through each.

As a side note - these can be piggybacked off of each other


#Cleans out old logs
sudo journalctl --vacuum-size=500M

echo "journal logs are cleaned up"

echo "Try cleaning up these files"
ls -lah | grep "\.sql"
ls -lah | grep .gz
echo "Or cleaning up these folders"
sudo du -ch -l  /home | grep "\.trash"
sudo du -ch -l  /home | grep staging

1 Like

Thanks for your contribution <3

This topic was automatically closed 3 hours after the last reply. New replies are no longer allowed.