Hi Michael,
MySQL date and *NIX OS date is not of the same format, as you seeing in
your case, too
You could have MySQL supply you with a date, not server OS.
In KSH script this is going to look like:
date_to_purge=$(mysql -uroot --password=mypassword test --silent -e
"SELECT CURDATE() - 7" )
and use $date_to_purge variable instead of $myDate
Best,
Mikhail Berman
Michael R Kirkpatrick wrote:
> All,
>
> End goal: rotate binary logs automatically with a script.
>
> Environment: Linux MySQL 5.0.45 master-master replication cluster
>
> I have modified a shell script to check the status of slaves IO thread
> running (Yes or No). If the status of replication is OK then the script
> tells the master to PURGE_BINARY_LOGS BEFORE *date*. I'm confident from
> the history of my replication that one week is enough time for any
> slaves to replay logs and catch up to where the master is. I'm having
> trouble with the syntax in the script: I want to tell MySQL to purge
> logs before *today minus 7*
>
> This script successfully emails me a correctly formatted message but the
> command-line mysql statement is returning the wrong format for date. Can
> anyone assist with formatting this statement to pass via command line
> the command to MySQL: PURGE_BINARY_LOGS BEFORE "one week before today" ;
>
> Too new to shell scripting to get it so far ...
>
>
> Part of script that I want to handle this:
>
>
> myDate="($(date)-7)"
>
> if [ $status = 0 ]; then
> mysql -uroot --password=mypassword test -e "PURGE_BINARY_LOGS BEFORE
> '($myDate)';"
> purge=$purge"date: `date`\n"
> echo -e $purge >>purge.txt
> for j in $email; do
> mail -s "$repl_stat MySQL Replication logs purged " $j < purge.txt
> done
> fi
>
>
>
>
> Thanks for any tips!
>
>
>
> Michael Kirkpatrick
> Systems Administrator
> MicroElectronics, Inc.
> mkirkpatrick@stripped
>
>
>
>