Support » Plugin: Log cleaner for iThemes Security » PHP Snippet to Delete Logs After X Days

  • jetxpert

    (@jetxpert)


    Good Day (and Happy Father’s Day, y’all)!

    Hey, was wondering if you can integrate into your plugin – or provide in this forum – a snippet (PHP code) that will automatically delete the iThemes Security logs after x number of days?

    Would be extremely useful and keep us from manually deleting the logs.

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • jetxpert

    (@jetxpert)

    Adding to my previous request …

    I assume two things would be needed here:

    (1) A snippet (PHP code) that deletes the affected database (“wp_***_itsec_logs) files.

    (2) A cron job that would execute the snippet every x number of days.

    Cheers!

    jetxpert

    (@jetxpert)

    Found the answer. Sharing. All we need is Cron Job to perform the above task.

    Here’s the Cron Job (MySQL) command:

    mysql -uDBUSERNAME -pDBPASSWORD -hlocalhost -e"truncate table TABLENAME" DBNAME

    Input Fields:

    DBUSERNAME: Database Username
    DBPASSWORD: Database Password
    TABLENAME: Name of iThemes Database Logs Table. In our case, “wp_***_itsec_logs”
    DBNAME: Top Level (Main) Database Name (which includes the itsec_logs table)

    Your hosting company can provide the above info (Input Fields) and help you set up the Cron Job.

    If you don’t want the Cron Job to send you a confirmation email every time it fires, append this to the end of the above command: >/dev/null 2>&1 to finally obtain:

    mysql -uDBUSERNAME -pDBPASSWORD -hlocalhost -e"truncate table TABLENAME" DBNAME >/dev/null 2>&1

    Last, we want the Cron Job to run every three (3) days, so use 0 0 */3 * * when running the job.

    That does it. Hope this helps the “Clear Logs” fans out there.

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.