logo
. . .

How to clean all log files in CP or CyberPanel

Step 1: Login as root user via ssh or if you sudo user then type:

sudo -i (root user did not require this command)
cd /root/
nano clearlog.sh


Step 2: Paste this code:

#!/bin/bash
# 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

Step 3: After you have to give permissions to the executable file

chmod +x clearlog.sh


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

sh clearlog.sh


Step 5: We can also automate cleanup using a cron

crontab -e

At the end of the file add

TO run DAILY : 0 0 * * * /root/clearlog.sh > /dev/null 2>&1
TO run Weekly : 0 0 * * 0 /root/clearlog.sh > /dev/null 2>&1
TO run Monthly: 0 0 1 * * /root/clearlog.sh > /dev/null 2>&1

Please rate this article to help us improve our Knowledge Base.

1 0