#!/bin/sh 

DIR=${1:-/opt/continuent} 

if [[ -d "$DIR" ]]; then 
echo "Patching all mysql_checker_query.sql script and template files found under directory $DIR\n"; 
#find /opt/continuent/ -name "*mysql_checker_query.sql*" -print 
find /opt/continuent/ -name "*mysql_checker_query.sql*" -print -exec perl -pi -w -e 's/greatest.*?relative_latency`,/greatest(0, t.applied_latency + (case when (now() - t.update_timestamp) > 0 then (now() - t.update_timestamp) else 0 end)) `relative_latency`,/;' {} \; 
else 
echo "Unable to locate directory $DIR\n"; 
exit 1; 
fi
