Many Thanks to Dobromir Velev,
And for those without PERL but with PHP (or prefer PHP) here is a quick and
dirty port to PHP
**** REMEMBER TO MAKE A BACKUP OF YOUR FILES BEFORE TESTING OR USING THIS
SCRIPT ****
**** IT IS RECOMMENDED YOU TEST THIS SCRIPT IN A NON PRODUCTION ENVIRONMENT
FIRST ****
**** USE AT YOUR OWN RISK, THERE IS NO WARRANTY EXPRESS OR IMPLIED WITH THIS
SOFTWARE ****
Cheers
Dean
<--- Script Starts --->
#!/usr/bin/php -q
<?php
# Remove the first line if you are running this through a browser
# Author Dean Urmson <durmson (_A_T_) mistral-networks (_D_O_T_) co
(_D_O_T_) uk>
# PHP Port of Original PERL script by Dobromir Velev <mysql (_A_T_) awebhome
(_D_O_T_) net>
$db_host="<your host here, maybe localhost>";
$db_user="<your mysql username here>";
$db_pass="<your mysql password here>";
$query="show master logs" ;
$dbh=NULL ;
$to_email='<Your email address here>';
$from_email='<Your From email address here>';
$email_subject='DB Clean error - '.date( 'l Y-m-d H:i:s T', time()) ;
$log = array() ;
// Leave the last x logs
$num_logs_to_leave = 7 ;
function controlled_die( $message = NULL ) {
global $dbh, $to_email, $from_email, $email_subject ;
if( is_null( $message ) ) {
$message = "MySQL ERROR: (".mysql_errno($dbh).")
".mysql_error($dbh);
}
$headers = "From: $from_email\r\n" ;
$headers .= "Reply-to: $from_email\r\n" ;
mail( $to_email, $email_subject, $message, $headers ) ;
exit;
} // end function Controlled_die
$dbh = mysql_connect($db_host, $db_user, $db_pass)
or controlled_die() ;
$result = mysql_query($query)
or controlled_die();
$rows = mysql_num_rows($result) ;
while ($num_logs_to_leave <= $rows){
$currRow = mysql_fetch_array($result,MYSQL_NUM) ;
$log[] = $currRow[0] ;
$num_logs_to_leave++;
}
mysql_free_result($result) ;
$message = "MySQL Log Purge Started :: ".date( 'l Y-m-d H:i:s T', time()) ;
$message .= "\nPurging logs to ".$log[count($log) - 1]."\n";
mysql_query("purge master logs to '".$log[count($log) - 1]."'") or
controlled_die();
mysql_close($dbh) ;
$message .= "Logs purge end: ".date( 'l Y-m-d H:i:s T', time())."\n";
$email_subject='MySQL Log Purge Report' ;
controlled_die($message);
?>
<--- Script Ends --->
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]