tags:

views:

29

answers:

3

The MySQL dump backup file has the following line...

# head -40 backup20-Apr-2010-07-32.sql | grep 'CHANGE MASTER TO '
-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000068', MASTER_LOG_POS=176357756;

a) I need to complete the statement with the parameters like Master host, user and password.

b) I do also need to remove the comment "--"

The line should look something like this...

CHANGE MASTER TO MASTER_HOST='111.222.333.444', MASTER_USER='slave_user', MASTER_PASSWORD='slave_user', MASTER_LOG_FILE='mysql-bin.000068', MASTER_LOG_POS=176357756;
A: 
  head -40 backup20-Apr-2010-07-32.sql |
  grep 'CHANGE MASTER TO ' |
  perl -lpe "s/-- CHANGE MASTER TO/CHANGE MASTER TO MASTER_HOST='111.222.333.444', MASTER_USER='slave_user', MASTER_PASSWORD='slave_user',/"
Chris Dolan
A: 
head -40 ORS20-Apr-2010-07-32.sql | grep 'CHANGE MASTER TO ' | sed 's/CHANGE MASTER TO/CHANGE MASTER TO MASTER_HOST='111.222.333.444', MASTER_USER='slave_user', MASTER_PASSWORD='slave_user'/g' | sed 's/^--//g'

Is it the correct way to do this?

shantanuo
The problem is that the single inverted comma is not preserved. # correct # MASTER_HOST='111.222.333.444' #result that I am getting is # MASTER_HOST=111.222.333.444
shantanuo
Use double quotes for the outer quotes: `echo "abc"|sed "s/b/'/"` or quote and escape the single quote: `echo "abc"|sed 's/b/'\''/'`
Dennis Williamson
Thanks a lot. double quotes, I will try to remember.
shantanuo
A: 
#!/bin/bash

s="MASTER_HOST='111.222.333.444', MASTER_USER='slave_user',"
awk -vs="$s" ' /-- CHANGE MASTER TO/{
  gsub("-- CHANGE MASTER TO","CHANGE MASTER TO "s)
}1 ' file >temp
mv temp file
ghostdog74