Steps to remove large error_log files from cPanel accounts

Steps to remove large error_log files from cPanel accounts

Steps to remove large error_log files from cPanel accounts

Error_log files contain the files with the errors encountered by the operating system, application or server while performing operations. Error_log is used for troubleshooting and managing servers, system and networks. This file is deleted in five days. Configuration corruption and table corruption are the common entries of these files.

When your server has many accounts, error_log files will consume a lot of disk space. So a lot of space in the error log file in each account will be wasted. Now we can see “How to remove large error_log files from cPanel accounts with a single command or automatic removal CRON JOB.

Removing error_log files with find command

Here we are going to used find command to list and remove the error_log file from the home directory. Find a command is a tool used for searching in Linux/Unix. Many options are available with this command and also used with bash scripting.
SSH is used as a root user and error_log files are listed with is disk space.

Code:
# find /home -type f -iname error_log -exec du -sh {} \;
-type specifies the find type.–iname specifies the find name. –exec executes the dus –sh and gives the list of the output along with its file size.

Let us see a sample output

Code:
# find /home -type f -iname error_log -exec du -sh {} \;
4.0K    /home/serf/public_html/wp-admin/error_log
4.0K    /home/serf/public_html/wp-includes/error_log
16K     /home/12erf/public_html/error_log
8.0K    /home/12erf/public_html/wp-content/plugins/LayerSlider/wp/error_log
4.0K    /home/tuy/public_html/wp-content/plugins/LayerSlider/error_log
After finishing this, we have to delete those files. You can also recreate them if you wish.

Removing error_log files

Find command also has an option to remove or delete the contents of the error_log file from the home directory.

Code:
# find /home -type f -iname error_log –delete
-delete is a switch that is used to remove all the outputs from the find command.

Removing error_log files using CORNJOB

You can use CORNJOB to remove the error_log files with a weekly schedule. CORNJOB is used to schedule the task that is executed on the server. The task is either script or command. They are mostly used for system administration or automation. In an operating system like UNIX, Corn used to schedule jobs based on time. The tasks or jobs are known as CRONJOB. Daemon is a process that is executed in the background of the system. The background process executed in the CRONJOB is called crond. Crontab file is present in the /etc folder, which is used to write a name or command of the script executes as per the scheduled time. List of all the jobs and timers are available here.

Code:
/bin/find /home -type f -iname error_log –delete
Example

0 22 * * fri /bin/find /home -type f -name error_log –delete
0 22 **
schedules the timer. fri /bin/find /home -type f -name error_log –delete is a find command used to run in a command line.

This command removes all the error_log files, if you find any problem in a particular file you have to change the location of the file.
Author
bhawanisingh
Views
4,171
First release
Last update
Rating
0.00 star(s) 0 ratings
Top