Operating System & Version
CloudLinux 7.8
cPanel & WHM Version
88.0.13

panit

Active Member
Aug 14, 2013
35
1
58
cPanel Access Level
Reseller Owner
The size of error logs on my server are causing disk space problems. This problem has been mentioned many times here for years but the only suggestion is to rotate the logs, which won't help with disk space. I found this post that has a script to handle the files but I don't know enough in that coding language to use it. However, I can write a cron job in php to do what I want. My plan is to have the script cycle through all of the directories in /home/ and delete any error log files found that are above some size limit. I would only need to run the script once a week, or maybe even once a month. My question is if there is any reason why I would not want to do this?
 

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,297
1,259
313
Houston
This problem has been mentioned many times here for years but the only suggestion is to rotate the logs, which won't help with disk space.
Rotating logs does in fact help with disk space as normally they're compressed when rotated.

However, I can write a cron job in php to do what I want. My plan is to have the script cycle through all of the directories in /home/ and delete any error log files found that are above some size limit. I would only need to run the script once a week, or maybe even once a month. My question is if there is any reason why I would not want to do this?
Yea a huge one is you wouldn't necessarily want to get rid of relevant logs if there's an issue with the server, so say someone is currently having an issue on the server, and their log file is getting filled with errors constantly, or say you needed to go back and audit an issue with an account that happened say last week but you can't any longer because the logs have been removed.

The solution I would suggest is rotating + compressing. Then implement the cron job or script to delete the oldest compressed log file, maybe once monthly.
 

panit

Active Member
Aug 14, 2013
35
1
58
cPanel Access Level
Reseller Owner
Rotating logs does in fact help with disk space as normally they're compressed when rotated.
Last, week, I deleted an error log file that was over 5 GB. Even if that reduced to half with compression, it is a lot of wasted space.

I understand what you are saying about deleting the log and then having some problem occur, but I think that unlikely if I delete the files once a month. But if I rotate the logs and then delete the last one as you mentioned, that might be the best of both options as long as I can limit the size when rotating. I haven't tried it yet but if I can rotate at 5 MB, which is still huge for such a file, then eventually that will keep the size down, I think.

I mainly just wanted to be sure that deleting files like that would not cause any server issues and it sounds like it would not from you reply. Thank you for the help.
 
  • Like
Reactions: cPanelLauren