Skip to main content

Bash script to find large error_log files? Run as cron?

Comments

6 comments

  • vacancy
    You may want to delete all the error_log files without making a size separation with a simpler logic.
    0 2 * * * rm -rf /home/*/public_html/error_log > /dev/null 2>&1
    All error_log files are deleted at 02.00 every night.
    0
  • sneader
    You may want to delete all the error_log files without making a size separation with a simpler logic.

    No, I don't want to automatically delete the files. As I mentioned, I want to proactively help customers troubleshoot any problems that are causing the error_log files in the first place. Plus, I think it is rude to delete these files without notifying customers, as they might be actively troubleshooting their own problems and will not be happy to find their error_log files magically gone. Thanks, though. - Scott
    0
  • vacancy
    Deleting files does not mean that you have disabled the error_log system. If there is an error, the files are automatically re-created. You can keep the deletion intervals longer.
    0
  • vacancy
    The following command might work. ATTENTION: Please try first on your test server.
    find /home/*/public_html -size +50M -name "error_log" -exec rm -rf {} \;
    0
  • sneader
    I have this working now, for anyone that is interested in getting a regular report of large error_log files: First, create this script, name it find-big-errorlogs.sh (or whatever) and put it somewhere handy (maybe /root/ ?). Set it to 755 permissions.
    #!/bin/bash find /home/*/public_html/ -type f -iname error_log -size +50M -exec du -sh {} \; | /bin/mail -s "myserver Big error_logs" you@example.com
    Replace 'myserver' with maybe the hostname of your server, to remind you which server this report is for. Replace 'you@example.com' with whatever email address you want to receive the report. Replace '50M' with whatever size you want to look for. If you want only 100MB or larger files, change it to 100M. Next, add the script to your crontab. Just run crontab -e, and to have it run at 3AM every Sunday morning, add something like:
    #!/bin/bash 0 3 * * 6 /root/find-big-errorlogs.sh
    Now you will get a list of large error_logs, to do with as you see fit. - Scott
    0
  • cPanelMichael
    Hello Scott, I'm happy to see you found a viable solution. Thank you for updating this thread with the outcome.
    0

Please sign in to leave a comment.