Managing disk space efficiently is an important step in maintaining the performance of your CWP (Control WebPanel) server. One common way to free up disk space is by clearing old or unnecessary log files.
In this tutorial, we’ll guide you through two solutions for clearing all log files on your CWP server without impacting its services. We’ll also provide instructions for automating the process using cron jobs.
Requirements
Before proceeding, ensure that you are logged in as the root user via SSH. This is necessary to execute the commands and scripts described in this guide.
Create a Log Clearing Script
To create a log clearing script and free up disk space, follow the steps below:
1. Create a Script File
Navigate to the /root directory and create a new file:
cd /root
nano clearlog.sh
2. Add the Bash Script
Open the file in a text editor and paste the following bash script:
#!/bin/bash
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
truncate -s 0 /usr/local/cwpsrv/var/services/roundcube/logs/errors
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-*
rm -rf /var/lib/clamav/tmp.*
3. Set Permissions
Ensure the script has executable permissions by running the following command:
chmod 755 /root/clearlog.sh
4. Execute the Script
Run the script to clear all logs:
sh /root/clearlog.sh
Once executed, the logs will be cleared. You can verify this by checking the log file locations.
Automating the Process with Cron Jobs
To regularly clear log files, you can set up a cron job. This will automate the execution of the log-clearing script according to a schedule that suits your needs.
1. Daily
To run the script daily, add this entry to your crontab:
0 0 * * * /usr/bin/sh /root/clearlog.sh
2. Weekly
To run the script weekly:
0 0 * * 0 /usr/bin/sh /root/clearlog.sh
3. Monthly
To run the script monthly:
0 0 1 * * /usr/bin/sh /root/clearlog.sh
Use the schedule that best fits your server’s log management requirements.
Summary
By following this guide, you can effectively manage log files on your CWP server and ensure optimal use of disk space. Whether you use a pre-written script or create your own, these solutions provide a straightforward way to keep your server running smoothly.
You May Also Like
- Domain Authority 101: What Every Website Owner Should Know
- 5 Website Design Pitfalls That Can Put Your Business at Risk
- How to Enable TLS 1.3 in Apache on CWP (Control Web Panel) for CentOS 7/8 or EL7/EL8
- How to Update Nginx to the Latest Official Version on CentOS 8 (EL8) / CWP
- Domain Name Appraisal: A Beginner’s Guide to Uncovering Value
