Strategical Shell Scripting For MySql Replication

Hi to all guyz ,
As i'm new to Shell scripting i was been working out to write a shell script for mysql Replication for multiple slave master architecture.i have done the process up with a script of 200 lines but still there are some things which can make my script more effective so i want your help to solve this script run like a pro

here is the problem i'm facing now

there is a table in the database by name Ipmonitor and in that i have a master ip and some slave ip's and the slave status will be in "0" and master ip will be as "1".if my master ip gets down it will check for a good slave to make it as new master and it deletes the old master record in the table and assigns new master's status as "1".after that selected ip will be the new master .now the real problem starts is dat i want to write a for loop to checkout the ip's and make the other ip's to route to the new master ip....so how can i write the shell script to check the slaves present apart from the ip which has been changed from slave to master.

Advance thanks to guys who help me out in this problem

Welcome to the forums! :slight_smile:

I dont fully understand the problem. Are you saying the slaves or other hosts should be updated with the information on which master it has to look to. Without going to the details of implementation, it looks like that is not the way right way of doing it. Slave should be agnostic of who the master is. Slave should hit a common interface something like a DNS that should take care of taking the packets or connecting to the 'then' master or 'then' super master and slave should not be knowing that information at all.

I might have misunderstood, sorry.

Hmm actually i'm building up a inteligent monitoring system which checks the architecture every 5secs through cron job......now the script checks up for the slave having up the recent and last log position of the master in to the slave and then we will make that slave as the new master and the other slaves should route up to the new master.the fetching up of the rite slave will be done with the interface of the database.now i want to make other slave ip's to route out to the new master ip.here i want to write a looping statement to check the ip's present in the table and execute some commands on the slave machines

I haven't understood the problem completely.

So, where is that you are stuck actually?

while read :
do
<scan_table_or_data_source>
<determine_master_or_slave>
<execute_commands>
sleep +n # if needed
done
select * from ipmonitor;
+------+-----------+---------+--------+
| id   | ip        | filepos | status |
+------+-----------+---------+--------+
|    1 | 10.0.0.20 |     109 |      1 |
|    2 | 10.0.0.21 |     122 |      0 |
|    3 | 10.0.0.22 |     125 |      0 |
+------+-----------+---------+--------+
3 rows in set (0.00 sec)

the above given was the table having the ip's where the ip having the status 1 will be the new master and the ip's wid '0' will be the slaves and here i should write a for loop to check every ip to execute the commands in making the slaves route to new master ip based on the status value '0' which is assigned for slave ip's!!!!

thank you dude....... your help made me to solve half of the problem in the script.....now my code was done and working like a pro!!!!!!!!