How to clean all log files in CWP or CWP Pro or Control Web Panel
Step 1: Login into your server via SSH then first create a file in /root dir :
cd /root
nano clearlog.sh
Step 2: Then paste this Bash script and save it by press ctrl+x:
#!/bin/bash
# Truncate various system logs
# truncate -s 0 /opt/nvm/.pm2/logs/*log
truncate -s 0 /usr/local/apache/logs/*bytes
truncate -s 0 /usr/local/apache/logs/*log
truncate -s 0 /usr/local/apache/domlogs/*bytes
truncate -s 0 /usr/local/apache/domlogs/*log
truncate -s 0 /var/log/messages
truncate -s 0 /var/log/maillog
truncate -s 0 /var/log/*log
truncate -s 0 /opt/alt/*/usr/var/log/php-fpm.log
truncate -s 0 /usr/local/cwpsrv/logs/access_log
truncate -s 0 /usr/local/cwpsrv/logs/error_log
truncate -s 0 /var/log/cron
truncate -s 0 /var/log/secure
truncate -s 0 /var/log/cwp/services_action.log
truncate -s 0 /var/log/cwp/cwp_sslmod.log
truncate -s 0 /var/log/cwp/cwp_cron.log
truncate -s 0 /var/log/cwp/cwp_backup.log
truncate -s 0 /var/log/cwp/activity.log
# Remove old logs
rm -rf /var/log/maillog-*
rm -rf /var/log/monit.log-*
rm -rf /var/log/spooler-*
rm -rf /var/log/messages-*
rm -rf /var/log/secure-*
rm -rf /var/log/pureftpd.log-*
rm -rf /var/log/yum.log-*
rm -rf /var/log/monit.log-*
rm -rf /var/log/cron-*
# --- MariaDB Log Cleanup ---
# truncate -s 0 /var/log/mariadb/mariadb.log
truncate -s 0 /var/lib/mysql/mysql.log
truncate -s 0 /var/lib/mysql/mysql-slow.log
rm -f /var/lib/mysql/mysql-bin.*
Step 3: Change the permission
chmod 755 /root/clearlog.sh
Step 4: Now run this command to run the clear log script
sh /root/clearlog.sh
Thats it the logs will be cleared you can go and check to the respected locations of the log.
Step 5: Cron Job
You can also create cron job like below by following solution 2 and create this cron job task according to your needs :
TO run DAILY :
0 0 * * * /usr/bin/sh /root/clearlog.sh
TO run Weekly :
0 0 * * 0 /usr/bin/sh /root/clearlog.sh
TO run Monthly:
0 0 1 * * /usr/bin/sh /root/clearlog.sh
You did a great job it will save lot's of space for you from your server.