# Appendix B
Scenario Scripts

## B.1. Introduction

This appendix gives scripts of scenarios which are described in [Empress Replication Scenarios]. Some of the operations have pre-steps that shall be executed before the operation. The lines starting with "#" are comments. Most of the environment variable settings are assumed to be set in a Bourne Shell or Korn Shell. If they are to be used in C Shell, the environment variable settings must be changed accordingly.

### B.1.1 Environment Variables that need to be set by User

These setting are common for all the scenarios. These are the environemnt variables that are going to be used by the scenarios. The values of some of these environment variables shall be set before executing the scenario operations.

    #!/bin/sh

    # Set the following variables to their appropriate values:
    # Directories, Host Names, Replication Master Server Names

    # ___Directories_______________________
    # Set these variables to the path of the database directory
    # Their default value is the current directory.
    # For example if Database directory for TorontoDB is
    # "/usr/empress/data/TorontoDB", then TORONTOPWD must be set to
    # "/usr/empress/data"
    #
       TORONTOPWD=`pwd`
          export TORONTOPWD
       NEWYORKPWD=`pwd`
          export NEWYORKPWD
       BROOKLYNPWD=`pwd`
          export BROOKLYNPWD
       TOKYOPWD=`pwd`
          export TOKYOPWD

    # __Host Names_____________________________________________
    # These will contain the network address and host names of their corresponding
    # hosts. Their default is localhost
    # For example if the host that TorontoDB will reside is "toronto.empress.com",
    # then TORONTOHOST must be set to "toronto.empress.com" (or to "toronto" if
    # all the databases are using the same network domain).
    #
       TORONTOHOST=`hostname`
          export TORONTOHOST
       NEWYORKHOST=`hostname`
          export NEWYORKHOST
       BROOKLYNHOST=`hostname`
          export BROOKLYNHOST
       TOKYOHOST=`hostname`
          export TOKYOHOST

    # __Replication Master Servers___________
    # Name of the Replication Master Servers
    #
       TORONTOREPSERVER=TorontoRepServer
          export TORONTOREPSERVER
       NEWYORKREPSERVER=NewYorkRepServer
          export NEWYORKREPSERVER

### B.1.2 Other Environment Variables

These environment variables do not need to changed by user. Their value is taken from the Environment variables that are set before.

    # ___Others____________________________
    #
       SERVERTYPE=replication_master
          export SERVERTYPE
       NETSERVER="${HOME}/.empress/netserver.cfg"
          export NETSERVER

    # __DB Names________________________________________________
       TORONTODB="${TORONTOPWD}/TorontoDB"
          export TORONTODB
       NEWYORKDB="${NEWYORKPWD}/NewYorkDB"
          export NEWYORKDB
       BROOKLYNDB="${BROOKLYNPWD}/BrooklynDB"
          export BROOKLYNDB
       TOKYODB="${TOKYOPWD}/TokyoDB"
          export TOKYODB

    # __Table Names______________________________________________
       TORONTOPLIST=TorontoPList
          export TORONTOPLIST
       NEWYORKPLIST=NewYorkPList
          export NEWYORKPLIST
       BROOKLYNPLIST=BrooklynPList
          export BROOKLYNPLIST
       TOKYOPLIST=TokyoPList
          export TOKYOPLIST

    # __Access Information__________________________________________
    # These variables are to simplify typing the access information to
    # Replication Maste and Replication Replicates.
    #
       TORONTO_RM_INFO="'${TORONTOREPSERVER}':'${TORONTODB}':${TORONTOPLIST}"
          export TORONTO_RM_INFO
       NEWYORK_RR_INFO="'${NEWYORKHOST}':'${NEWYORKDB}':${NEWYORKPLIST}"
          export NEWYORK_RR_INFO
       NEWYORK_RM_INFO="'${NEWYORKREPSERVER}':'${NEWYORKDB}':${NEWYORKPLIST}"
          export NEWYORK_RM_INFO
       BROOKLYN_RR_INFO="'${BROOKLYNHOST}':'${BROOKLYNDB}':${BROOKLYNPLIST}"
          export BROOKLYN_RR_INFO
       TOKYO_RR_INFO="'${TOKYOHOST}':'${TOKYODB}':${TOKYOPLIST}"
          export TOKYO_RR_INFO

## B.2 Scenario A

### B.2.1 Operations for Creating the Scenario A

    #!/bin/sh

    # Set the following variables to their appropriate values:
    # Directories, Host Names, Replication Master Server Names

    # ___Directories_______________________
    # Set these variables to the path of the database directory
    # Their default value is the current directory.
    # For example if Database directory for TorontoDB is
    # "/usr/empress/data/TorontoDB", then TORONTOPWD must be set to
    # "/usr/empress/data"
    #
       TORONTOPWD=`pwd`
          export TORONTOPWD
       NEWYORKPWD=`pwd`
          export NEWYORKPWD
       BROOKLYNPWD=`pwd`
          export BROOKLYNPWD
       TOKYOPWD=`pwd`
          export TOKYOPWD

    # __Host Names_____________________________________________
    # These will contain the network address and host names of their corresponding
    # hosts. Their default is localhost
    # For example if the host that TorontoDB will reside is "toronto.empress.com",
    # then TORONTOHOST must be set to "toronto.empress.com" (or to "toronto" if
    # all the databases are using the same network domain).
    #
       TORONTOHOST=`hostname`
          export TORONTOHOST
       NEWYORKHOST=`hostname`
          export NEWYORKHOST
       BROOKLYNHOST=`hostname`
          export BROOKLYNHOST
       TOKYOHOST=`hostname`
          export TOKYOHOST

    # __Replication Master Servers___________
    # Name of the Replication Master Servers
    #
       TORONTOREPSERVER=TorontoRepServer
          export TORONTOREPSERVER
       NEWYORKREPSERVER=NewYorkRepServer
          export NEWYORKREPSERVER

    # ___Others____________________________
    #
       SERVERTYPE=replication_master
          export SERVERTYPE
       NETSERVER="${HOME}/.empress/netserver.cfg"
          export NETSERVER

    # __DB Names________________________________________________
       TORONTODB="${TORONTOPWD}/TorontoDB"
          export TORONTODB
       NEWYORKDB="${NEWYORKPWD}/NewYorkDB"
          export NEWYORKDB
       BROOKLYNDB="${BROOKLYNPWD}/BrooklynDB"
          export BROOKLYNDB
       TOKYODB="${TOKYOPWD}/TokyoDB"
          export TOKYODB

    # __Table Names______________________________________________
       TORONTOPLIST=TorontoPList
          export TORONTOPLIST
       NEWYORKPLIST=NewYorkPList
          export NEWYORKPLIST
       BROOKLYNPLIST=BrooklynPList
          export BROOKLYNPLIST
       TOKYOPLIST=TokyoPList
          export TOKYOPLIST

    # __Access Information__________________________________________
    # These variables are to simplify typing the access information to
    # Replication Maste and Replication Replicates.
    #
       TORONTO_RM_INFO="'${TORONTOREPSERVER}':'${TORONTODB}':${TORONTOPLIST}"
          export TORONTO_RM_INFO
       NEWYORK_RR_INFO="'${NEWYORKHOST}':'${NEWYORKDB}':${NEWYORKPLIST}"
          export NEWYORK_RR_INFO
       NEWYORK_RM_INFO="'${NEWYORKREPSERVER}':'${NEWYORKDB}':${NEWYORKPLIST}"
          export NEWYORK_RM_INFO
       BROOKLYN_RR_INFO="'${BROOKLYNHOST}':'${BROOKLYNDB}':${BROOKLYNPLIST}"
          export BROOKLYN_RR_INFO
       TOKYO_RR_INFO="'${TOKYOHOST}':'${TOKYODB}':${TOKYOPLIST}"
          export TOKYO_RR_INFO

    # --------------------------------------------------
    # Scenario A
    # --------------------------------------------------

    #
    # Presteps:
    #
    #  ${TORONTOHOST}: OpA1.1. Create Database ${TORONTODB}
       empmkdb ${TORONTODB}

    # $TORONTODB: OpA1.2. create table ${TORONTOPLIST}
    empbatch ${TORONTODB} << @
       create ${TORONTOPLIST} (\
             prod_id integer not null,  \
             prod_name character(30,1) not null, \
             prod_price float,\
             prod_lang character(15,1));
    @

    # "$TORONTODB: OpA1.3. insert data into ${TORONTOPLIST}"
    empbatch ${TORONTODB} << @
       insert into ${TORONTOPLIST} values (1, 'DB1', 4000, 'english');
       insert into ${TORONTOPLIST} values (3, 'DB2', 7000, 'english');
    @

    # "$NEWYORKHOST:  OpA1.4. Create database ${NEWYORKDB}"
       empmkdb ${NEWYORKDB}

    # "------------------- OpA1 ------------------------------------"

    # "${TORONTODB}: OpA1. Define master table [${TORONTOPLIST}] "
    empbatch ${TORONTODB} << @
       alter ${TORONTOPLIST} change table type to MASTER;
    @

    # "------------------- OpA2 ------------------------------------"

    # "${TORONTOHOST}: OpA2. Configure Network Server on RMT Side [${TORONTOREPSERVER}] "

    # "OpA2.1 Network Server Config File"
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVER} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpA3 ------------------------------------"

    # "${TORONTOHOST}: OpA3. Start Replication Master Server ${TORONTOREPSERVER}"
       empsvadm ${TORONTOREPSERVER} start

    # "------------------- OpA4 ------------------------------------"

    # "${TORONTODB}: OpA4.
    #  Create Replication Replicate [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    empbatch ${TORONTODB} << @
        create replication replicate \
         ${NEWYORK_RR_INFO} \
         ON ${TORONTOPLIST};
    @

    # "------------------- OpA5 ------------------------------------"

    # Steps of OpA5 are to be executed if ${NEWYORKHOST} and ${TORONTOHOST} are
    # different. Otherwise, these is no need to create the files once more.

    # "${NEWYORKHOST}: OpA5.  Configure Network Server on RRT Side [${NEWYORKPLIST}] "
    # "OpA6.1 Network Server Config File"
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVER} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpA6 ------------------------------------"

    # "${NEWYORKDB}: OpA6. Create Replicate Table [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    empbatch ${NEWYORKDB} << @
       create replicate table \
            ${NEWYORKPLIST}  \
            FROM ${TORONTO_RM_INFO};
    @

    # "------------------- OpA7 ------------------------------------"

    # "${NEWYORKHOST}: OpA7. Perform a Synchronization [${NEWYORKPLIST}]"
       emprepsync -v ${NEWYORKDB} ${NEWYORKPLIST}

    # "------------------- OpA8 ------------------------------------"

    # "$NewYorkDB: OpA8. View Replication Table and Synchronization Status [NewYorkPList] "
    empbatch ${NEWYORKDB} << @
       display table ${NEWYORKPLIST}  all;
    @

    # "Check the contents of the Replication Replicate Table NewYorkPList"
    empbatch ${NEWYORKDB} << @
       select * from ${NEWYORKPLIST};
    @

### B.2.2 Other possible operations in scenario A

    # "${NEWYORKDB}: Drop Replicate Table [${NEWYORKPLIST}] "
    #   empcmd ${NEWYORKDB} "DROP TABLE ${NEWYORKPLIST};"

    # "${TORONTODB}: Unauthorize Replication Replicate [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    #   empcmd ${TORONTODB} "DROP REPLICATION REPLICATE \
    #         ${NEWYORK_RR_INFO} \
    #          ON ${TORONTOPLIST};"

    # "------------------- OpA9 ------------------------------------"

    # "${TORONTOHOST}: OpA9. Stop Replication Master Server [${TORONTOREPSERVER}]"
       empsvadm ${TORONTOREPSERVER} stop

    # "${TORONTODB}: Undefine Master Table [${TORONTOPLIST}]"
    #   empcmd ${TORONTODB} "ALTER TABLE ${TORONTOPLIST} CHANGE TABLE TYPE TO NORMAL;"

    #---------------------------------------------------------------
    # "Post Steps to completely clear the effects"

    # "Remove database ${NEWYORKDB}"
    #   emprmdb ${NEWYORKDB}
    # "Remove database ${TORONTODB}"
    #   emprmdb ${TORONTODB}
    # "remove server log file"
    #   rm ${TORONTOREPSERVER}.log

## B.3 Scenario B

### B.3.1 Operations for Creating the Scenario B

    #!/bin/sh

    # Set the following variables to their appropriate values:
    # Directories, Host Names, Replication Master Server Names

    # ___Directories_______________________
    # Set these variables to the path of the database directory
    # Their default value is the current directory.
    # For example if Database directory for TorontoDB is
    # "/usr/empress/data/TorontoDB", then TORONTOPWD must be set to
    # "/usr/empress/data"
    #
       TORONTOPWD=`pwd`
          export TORONTOPWD
       NEWYORKPWD=`pwd`
          export NEWYORKPWD
       BROOKLYNPWD=`pwd`
          export BROOKLYNPWD
       TOKYOPWD=`pwd`
          export TOKYOPWD

    # __Host Names_____________________________________________
    # These will contain the network address and host names of their corresponding
    # hosts. Their default is localhost
    # For example if the host that TorontoDB will reside is "toronto.empress.com",
    # then TORONTOHOST must be set to "toronto.empress.com" (or to "toronto" if
    # all the databases are using the same network domain).
    #
       TORONTOHOST=`hostname`
          export TORONTOHOST
       NEWYORKHOST=`hostname`
          export NEWYORKHOST
       BROOKLYNHOST=`hostname`
          export BROOKLYNHOST
       TOKYOHOST=`hostname`
          export TOKYOHOST

    # __Replication Master Servers___________
    # Name of the Replication Master Servers
    #
       TORONTOREPSERVER=TorontoRepServer
          export TORONTOREPSERVER
       NEWYORKREPSERVER=NewYorkRepServer
          export NEWYORKREPSERVER

    # ___Others____________________________
    #
       SERVERTYPE=replication_master
          export SERVERTYPE
       NETSERVER="${HOME}/.empress/netserver.cfg"
          export NETSERVER

    # __DB Names________________________________________________
       TORONTODB="${TORONTOPWD}/TorontoDB"
          export TORONTODB
       NEWYORKDB="${NEWYORKPWD}/NewYorkDB"
          export NEWYORKDB
       BROOKLYNDB="${BROOKLYNPWD}/BrooklynDB"
          export BROOKLYNDB
       TOKYODB="${TOKYOPWD}/TokyoDB"
          export TOKYODB

    # __Table Names______________________________________________
       TORONTOPLIST=TorontoPList
          export TORONTOPLIST
       NEWYORKPLIST=NewYorkPList
          export NEWYORKPLIST
       BROOKLYNPLIST=BrooklynPList
          export BROOKLYNPLIST
       TOKYOPLIST=TokyoPList
          export TOKYOPLIST

    # __Access Information__________________________________________
    # These variables are to simplify typing the access information to
    # Replication Maste and Replication Replicates.
    #
       TORONTO_RM_INFO="'${TORONTOREPSERVER}':'${TORONTODB}':${TORONTOPLIST}"
          export TORONTO_RM_INFO
       NEWYORK_RR_INFO="'${NEWYORKHOST}':'${NEWYORKDB}':${NEWYORKPLIST}"
          export NEWYORK_RR_INFO
       NEWYORK_RM_INFO="'${NEWYORKREPSERVER}':'${NEWYORKDB}':${NEWYORKPLIST}"
          export NEWYORK_RM_INFO
       BROOKLYN_RR_INFO="'${BROOKLYNHOST}':'${BROOKLYNDB}':${BROOKLYNPLIST}"
          export BROOKLYN_RR_INFO
       TOKYO_RR_INFO="'${TOKYOHOST}':'${TOKYODB}':${TOKYOPLIST}"
          export TOKYO_RR_INFO

    # --------------------------------------------------
    # Scenario B
    # --------------------------------------------------

    #
    # Presteps:
    #
    # " ${TORONTOHOST}: OpB1.1. Create Database ${TORONTODB}"
       empmkdb ${TORONTODB}

    # "$TORONTODB: OpB1.2. create table ${TORONTOPLIST}"
    empbatch ${TORONTODB} << @
       create ${TORONTOPLIST} (\
             prod_id integer not null,  \
             prod_name character(30,1) not null, \
             prod_price float,\
             prod_lang character(15,1));
    @

    # "$TORONTODB: OpB1.3. insert data into ${TORONTOPLIST}"
    empbatch ${TORONTODB} << @
       insert into ${TORONTOPLIST} values (1, 'DB1', 4000, 'english');
       insert into ${TORONTOPLIST} values (3, 'DB2', 7000, 'english');
    @

    # "$NEWYORKHOST:  OpB1.4. Create database ${NEWYORKDB}"
       empmkdb ${NEWYORKDB}

    # "------------------- OpB1 ------------------------------------"

    # "${TORONTODB}: OpB1. Define master table [${TORONTOPLIST}] "
    empbatch ${TORONTODB} << @
       alter ${TORONTOPLIST} change table type to MASTER;
    @

    # "------------------- OpB2 ------------------------------------"

    # "${TORONTOHOST}: OpB2. Configure Network Server on RMT Side [${TORONTOREPSERVER}] "

    # "OpB2.1 Network Server Config File"
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVER} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpB3 ------------------------------------"

    # "${TORONTOHOST}: OpB3. Start Replication Master Server ${TORONTOREPSERVER}"
       empsvadm ${TORONTOREPSERVER} start

    # "------------------- OpB4 ------------------------------------"

    # "${TORONTODB}: OpB4.
    #  Create Replication Replicate [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    empbatch ${TORONTODB} << @
       create replication replicate \
         ${NEWYORK_RR_INFO} \
         ON ${TORONTOPLIST};
    @

    # "------------------- OpB5 ------------------------------------"

    # Steps of OpB5 are to be executed if ${NEWYORKHOST} and ${TORONTOHOST} are
    # different. Otherwise, these is no need to create the files once more.

    # "${NEWYORKHOST}: OpB5.  Configure Network Server on RRT Side [${NEWYORKPLIST}] "
    # "OpB5.1 Network Server Config File"
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVER} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpB6 ------------------------------------"

    # "${NEWYORKDB}: OpB6. Create Replicate Table and Load Data [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    empbatch ${NEWYORKDB} << @
       create and insert into replicate table \
            ${NEWYORKPLIST}  \
            FROM ${TORONTO_RM_INFO};
    @

    # "------------------- OpB7 ------------------------------------"
    #
    # ${NEWYORKHOST}: OpB7. Configure Network Server on RMT Side (NewYorkRepServer)
    # "OpB7.1 Network Server Config File"
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat >>  ${NETSERVER} << @
    MSNETSERVER
        NAME=${NEWYORKREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${NEWYORKHOST}
        PORT_ADMIN=12350
        PORT_SERVICE=12355
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpB8 ------------------------------------"
    #
    # ${NEWYORKHOST}: OpB8. Start Replication Master Server (NewYorkRepServer)
       empsvadm ${NEWYORKREPSERVER} start

    # "------------------- OpB9 ------------------------------------"
    # ${NEWYORKDB}: OpB9. Create Replication Replicate (${BROOKLYNPLIST}, ${NEWYORKPLIST})
    empbatch ${NEWYORKDB} << @
       create replication replicate \
            ${BROOKLYN_RR_INFO} \
            ON ${NEWYORKPLIST};
    @

    # "------------------- OpB10 ------------------------------------"
    # ${BROOKLYNHOST}: OpB10.  Configure Network Server on RRT Side [${BROOKLYNPLIST}]

    # *******************  ATTENTION: ******************
    # Execute OpB10 only if ${NEWYORKHOST} is different from ${BROOKLYNHOST}
    # **************************************************

    # "OpB10.1 Network Server Config File"
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat >> ${NETSERVER} << @
    MSNETSERVER
        NAME=${NEWYORKREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${NEWYORKHOST}
        PORT_ADMIN=12350
        PORT_SERVICE=12355
    MSNETSERVEREND
    @

    # Pre-step 11.1: Create database ${BROOKLYNDB}
       empmkdb ${BROOKLYNDB}

    # "------------------- OpB11 ------------------------------------"
    # ${BROOKLYNDB}: OpB11. Create Replicate Table (${BROOKLYNPLIST}, ${NEWYORKPLIST})
    empbatch ${BROOKLYNDB} << @
       create and insert into replicate table \
           ${BROOKLYNPLIST} \
           FROM ${NEWYORK_RM_INFO};
    @

    # "------------------- OpB12 ------------------------------------"

    # "${BROOKLYNDB}: OpB12. View Replication Table and Synch [${BROOKLYNPLIST}] "
    empbatch ${BROOKLYNDB} << @
       display table ${BROOKLYNPLIST} all;
    @

    # "Check the contents of the Replication Replicate Table ${BROOKLYNPLIST}"
    empbatch ${BROOKLYNDB} << @
       select * from ${BROOKLYNPLIST};
    @

### B.3.3 Other possible operations in the scenario B

    # "${BROOKLYNDB}: Drop Replicate Table [${BROOKLYNPLIST}] "
    #   empcmd ${BROOKLYNDB} "DROP TABLE ${BROOKLYNPLIST};"

    # "${TORONTODB}: Unauthorize Replication Replicate [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    #   empcmd ${TORONTODB} "DROP REPLICATION REPLICATE \
    #         ${NEWYORK_RR_INFO} \
    #          ON ${TORONTOPLIST};"

    # "------------------- OpB13 ------------------------------------"

    # "${TORONTOHOST}: OpB13. Stop Replication Master Server [${TORONTOREPSERVER}]"
       empsvadm ${TORONTOREPSERVER} stop

    # "${TORONTODB}:  Undefine Master Table [${TORONTOPLIST}]"
    #   empcmd ${TORONTODB} "ALTER TABLE ${TORONTOPLIST} CHANGE TABLE TYPE TO NORMAL;"

    # "${NEWYORKDB}: Drop Replicate Table [${NEWYORKPLIST}] "
    #   empcmd ${NEWYORKDB} "DROP TABLE ${NEWYORKPLIST};"

    # "${NEWYORKDB}: Unauthorize Replication Replicate [${BROOKLYNPLIST}, ${NEWYORKPLIST}] "
    #   empcmd ${NEWYORKDB} "DROP REPLICATION REPLICATE \
    #         ${BROOKLYN_RR_INFO} \
    #          ON ${NEWYORKPLIST};"

    # "------------------- OpB14 ------------------------------------"

    # "${NEWYORKHOST}: OpB14. Stop Replication Master Server [${NEWYORKREPSERVER}]"
       empsvadm ${NEWYORKREPSERVER} stop

    #---------------------------------------------------------------
    # "Post Steps to completely clear the effects"

    # "Remove database ${NEWYORKDB}"
    #   emprmdb ${NEWYORKDB}
    # "Remove database ${TORONTODB}"
    #   emprmdb ${TORONTODB}
    # "Remove database ${BROOKLYNDB}
    #   emprmdb ${BROOKLYNDB}
    # "remove server log file"
    #   rm ${TORONTOREPSERVER}.log

## B.4 Scenario C

### B.4.1 Operations for Creating Scenario C

    #!/bin/sh

    # Set the following variables to their appropriate values:
    # Directories, Host Names, Replication Master Server Names

    # ___Directories_______________________
    # Set these variables to the path of the database directory
    # Their default value is the current directory.
    # For example if Database directory for TorontoDB is
    # "/usr/empress/data/TorontoDB", then TORONTOPWD must be set to
    # "/usr/empress/data"
    #
       TORONTOPWD=`pwd`
          export TORONTOPWD
       NEWYORKPWD=`pwd`
          export NEWYORKPWD
       BROOKLYNPWD=`pwd`
          export BROOKLYNPWD
       TOKYOPWD=`pwd`
          export TOKYOPWD

    # __Host Names_____________________________________________
    # These will contain the network address and host names of their corresponding
    # hosts. Their default is localhost
    # For example if the host that TorontoDB will reside is "toronto.empress.com",
    # then TORONTOHOST must be set to "toronto.empress.com" (or to "toronto" if
    # all the databases are using the same network domain).
    #
       TORONTOHOST=`hostname`
          export TORONTOHOST
       NEWYORKHOST=`hostname`
          export NEWYORKHOST
       BROOKLYNHOST=`hostname`
          export BROOKLYNHOST
       TOKYOHOST=`hostname`
          export TOKYOHOST

    # __Replication Master Servers___________
    # Name of the Replication Master Servers
    #
       TORONTOREPSERVER=TorontoRepServer
          export TORONTOREPSERVER
       NEWYORKREPSERVER=NewYorkRepServer
          export NEWYORKREPSERVER

    # ___Others____________________________
    #
       SERVERTYPE=replication_master
          export SERVERTYPE
       NETSERVER="${HOME}/.empress/netserver.cfg"
          export NETSERVER

    # __DB Names________________________________________________
       TORONTODB="${TORONTOPWD}/TorontoDB"
          export TORONTODB
       NEWYORKDB="${NEWYORKPWD}/NewYorkDB"
          export NEWYORKDB
       BROOKLYNDB="${BROOKLYNPWD}/BrooklynDB"
          export BROOKLYNDB
       TOKYODB="${TOKYOPWD}/TokyoDB"
          export TOKYODB

    # __Table Names______________________________________________
       TORONTOPLIST=TorontoPList
          export TORONTOPLIST
       NEWYORKPLIST=NewYorkPList
          export NEWYORKPLIST
       BROOKLYNPLIST=BrooklynPList
          export BROOKLYNPLIST
       TOKYOPLIST=TokyoPList
          export TOKYOPLIST

    # __Access Information__________________________________________
    # These variables are to simplify typing the access information to
    # Replication Maste and Replication Replicates.
    #
       TORONTO_RM_INFO="'${TORONTOREPSERVER}':'${TORONTODB}':${TORONTOPLIST}"
          export TORONTO_RM_INFO
       NEWYORK_RR_INFO="'${NEWYORKHOST}':'${NEWYORKDB}':${NEWYORKPLIST}"
          export NEWYORK_RR_INFO
       NEWYORK_RM_INFO="'${NEWYORKREPSERVER}':'${NEWYORKDB}':${NEWYORKPLIST}"
          export NEWYORK_RM_INFO
       BROOKLYN_RR_INFO="'${BROOKLYNHOST}':'${BROOKLYNDB}':${BROOKLYNPLIST}"
          export BROOKLYN_RR_INFO
       TOKYO_RR_INFO="'${TOKYOHOST}':'${TOKYODB}':${TOKYOPLIST}"
          export TOKYO_RR_INFO

    # --------------------------------------------------
    # Scenario C
    # --------------------------------------------------

    #
    # Presteps:
    #
    # " ${TORONTOHOST}: OpB1.1. Create Database ${TORONTODB}"
       empmkdb ${TORONTODB}

    # "$TORONTODB: OpB1.2. create table ${TORONTOPLIST}"
    empbatch ${TORONTODB} << @
       create ${TORONTOPLIST} (\
             prod_id integer not null,  \
             prod_name character(30,1) not null, \
             prod_price float,\
             prod_lang character(15,1));
    @

    # "$TORONTODB: OpB1.3. insert data into ${TORONTOPLIST}"
    empbatch ${TORONTODB} << @
       insert into ${TORONTOPLIST} values (1, 'DB1', 4000, 'english');
       insert into ${TORONTOPLIST} values (3, 'DB2', 7000, 'english');
    @

    # "$NEWYORKHOST:  OpB1.4. Create database ${NEWYORKDB}"
       empmkdb ${NEWYORKDB}

    # "------------------- OpB1 ------------------------------------"

    # "${TORONTODB}: OpB1. Define master table [${TORONTOPLIST}] "
    empbatch ${TORONTODB} << @
       alter ${TORONTOPLIST} change table type to MASTER;
    @

    # "------------------- OpB2 ------------------------------------"

    # "${TORONTOHOST}: OpB2. Configure Network Server on RMT Side [${TORONTOREPSERVER}] "

    # "OpB2.1 Network Server Config File"
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVER} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpB3 ------------------------------------"

    # "OpB3. Start Replication Master Server ${TORONTOREPSERVER}"
       empsvadm ${TORONTOREPSERVER} start

    # "------------------- OpB4 ------------------------------------"

    # "${TORONTODB}: OpB4.
    #  Create Replication Replicate [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    empbatch ${TORONTODB} << @
       create replication replicate \
         ${NEWYORK_RR_INFO} \
         ON ${TORONTOPLIST};
    @

    # "------------------- OpB5 ------------------------------------"

    # Steps of OpB5 are to be executed if ${NEWYORKHOST} and ${TORONTOHOST} are
    # different. Otherwise, these is no need to create the files once more.

    # "${NEWYORKHOST}: OpB5.  Configure Network Server on RRT Side [${NEWYORKPLIST}] "
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVER} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpB6 ------------------------------------"

    # "${NEWYORKDB}: OpB6. Create Replicate Table and Load Data [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    empbatch ${NEWYORKDB} << @
       create and insert into replicate table \
            ${NEWYORKPLIST}  \
            FROM ${TORONTO_RM_INFO};
    @

    # "------------------- OpB7 ------------------------------------"
    #
    # ${NEWYORKHOST}: OpB7. Configure Network Server on RMT Side (NewYorkRepServer)
    # "OpB7.1 Network Server Config File"
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat >>  ${NETSERVER} << @
    MSNETSERVER
        NAME=${NEWYORKREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${NEWYORKHOST}
        PORT_ADMIN=12350
        PORT_SERVICE=12355
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpB8 ------------------------------------"
    #
    # ${NEWYORKHOST}: OpB8. Start Replication Master Server (NewYorkRepServer)
       empsvadm ${NEWYORKREPSERVER} start

    # "------------------- OpB9 ------------------------------------"
    # ${NEWYORKDB}: OpB9. Create Replication Replicate (${BROOKLYNPLIST}, ${NEWYORKPLIST})
    empbatch ${NEWYORKDB} << @
       create replication replicate \
            ${BROOKLYN_RR_INFO} \
            ON ${NEWYORKPLIST};
    @

    # ------------------- OpB10 ------------------------------------

    # ${BROOKLYNHOST}: OpB10.  Configure Network Server on RRT Side [${BROOKLYNPLIST}]

    # *******************  ATTENTION: **********************
    #  Execute OpB10 only if ${NEWYORKHOST} is different from ${BROOKLYNHOST}
    # ******************************************************

    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVER} << @
    MSNETSERVER
        NAME=${NEWYORKREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${NEWYORKHOST}
        PORT_ADMIN=12350
        PORT_SERVICE=12355
    MSNETSERVEREND
    @

    # Pre-step 11.1: Create database ${BROOKLYNDB}
       empmkdb ${BROOKLYNDB}

    # "------------------- OpB11 ------------------------------------"
    # ${BROOKLYNDB}: OpB11. Create Replicate Table (${BROOKLYNPLIST}, ${NEWYORKPLIST})
    empbatch ${BROOKLYNDB} << @
       create and insert into replicate table \
           ${BROOKLYNPLIST} \
           FROM ${NEWYORK_RM_INFO};
    @

    # "------------------- OpC1  ------------------------------------"
    #
    # TORONTODB: OpC1. Create Replication Replicate (BROOKLYNPLIST, TORONTOPLIST)
    empbatch ${TORONTODB} << @
       CREATE REPLICATION REPLICATE \
           ${BROOKLYN_RR_INFO}  \
           ON ${TORONTOPLIST};
    @

    # "------------------- OpC2 ------------------------------------"
    # "${BROOKLYNHOST}: OpC2.  Configure Network Server on RRT Side [${BROOKLYNPLIST}] "
    # Execute step C2 only if ${TORONTOHOST} is different from ${BROOKLYNHOST}
    #
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat >> ${NETSERVER} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpC3  ------------------------------------"
    #
    # $BrooklynDB: OpC3. Create Replication Master (${TORONTOPLIST}, ${BROOKLYNPLIST})
    empbatch ${BROOKLYNDB} << @
       CREATE REPLICATION MASTER \
          ${TORONTO_RM_INFO} \
           ON ${BROOKLYNPLIST};
    @

    # "------------------- OpC4 ------------------------------------"
    #
    # "${BROOKLYNDB}: OpC4. View Replication Table and Synch Status [${BROOKLYNPLIST}] "
    empbatch ${BROOKLYNDB} << @
       display table ${BROOKLYNPLIST} all;
    @

    # "Check the contents of the Replication Replicate Table ${BROOKLYNPLIST}"
    empbatch ${BROOKLYNDB} << @
       select * from ${BROOKLYNPLIST};
    @

### B.4.2 Other possible operations in scenario C

    # "------------------------------------------------------------"
    # "the rest of the commands undo the effects of Scenario C"
    # "------------------------------------------------------------"

    # $BrooklynDB: Drop Replication Master (${BROOKLYNPLIST}, ${TORONTOPLIST})
    #   empcmd  ${BROOKLYNDB}  "DROP REPLICATION MASTER \
    #      ${TORONTO_RM_INFO} \
    #       ON ${BROOKLYNPLIST};"

    # "${TORONTODB}: Drop Replication Replicate [${TORONTOPLIST}, ${BROOKLYNPLIST}] "
    #   empcmd ${TORONTODB} "DROP REPLICATION REPLICATE \
    #         ${BROOKLYN_RR_INFO} \
    #         ON ${TORONTOPLIST};"

    # "${BROOKLYNDB}: Drop Replicate Table [${BROOKLYNPLIST}] "
    #   empcmd ${BROOKLYNDB} "DROP TABLE ${BROOKLYNPLIST};"

    # "${TORONTODB}:  Unauthorize Replication Replicate [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    #   empcmd ${TORONTODB} "DROP REPLICATION REPLICATE \
    #      ${NEWYORK_RR_INFO} \
    #      ON ${TORONTOPLIST};"

    # "${TORONTOHOST}:  Stop Replication Master Server [${TORONTOREPSERVER}]"
       empsvadm ${TORONTOREPSERVER} stop

    # "${TORONTODB}:  Undefine Master Table [${TORONTOPLIST}]"
    #   empcmd ${TORONTODB} "ALTER TABLE ${TORONTOPLIST} CHANGE TABLE TYPE TO NORMAL;"

    #---------------------------------------------------------------
    # "Post Steps to completely clear the effects"

    # "Remove database ${NEWYORKDB}"
    #   emprmdb ${NEWYORKDB}
    # "Remove database ${TORONTODB}"
    #   emprmdb ${TORONTODB}
    # "Remove database ${BROOKLYNDB}
    #   emprmdb ${BROOKLYNDB}
    # "remove server log file"
    #   rm ${TORONTOREPSERVER}.log

## B.5 Scenario D

### B.5.1 Operations for Creating the Scenario D

    #!/bin/sh

    # Set the following variables to their appropriate values:
    # Directories, Host Names, Replication Master Server Names

    # ___Directories_______________________
    # Set these variables to the path of the database directory
    # Their default value is the current directory.
    # For example if Database directory for TorontoDB is
    # "/usr/empress/data/TorontoDB", then TORONTOPWD must be set to
    # "/usr/empress/data"
    #
       TORONTOPWD=`pwd`
          export TORONTOPWD
       NEWYORKPWD=`pwd`
          export NEWYORKPWD
       BROOKLYNPWD=`pwd`
          export BROOKLYNPWD
       TOKYOPWD=`pwd`
          export TOKYOPWD

    # __Host Names_____________________________________________
    # These will contain the network address and host names of their corresponding
    # hosts. Their default is localhost
    # For example if the host that TorontoDB will reside is "toronto.empress.com",
    # then TORONTOHOST must be set to "toronto.empress.com" (or to "toronto" if
    # all the databases are using the same network domain).
    #
       TORONTOHOST=`hostname`
          export TORONTOHOST
       NEWYORKHOST=`hostname`
          export NEWYORKHOST
       BROOKLYNHOST=`hostname`
          export BROOKLYNHOST
       TOKYOHOST=`hostname`
          export TOKYOHOST

    # __Replication Master Servers___________
    # Name of the Replication Master Servers
    #
       TORONTOREPSERVER=TorontoRepServer
          export TORONTOREPSERVER
       NEWYORKREPSERVER=NewYorkRepServer
          export NEWYORKREPSERVER

    # ___Others____________________________
    #
       SERVERTYPE=replication_master
          export SERVERTYPE
       NETSERVER="${HOME}/.empress/netserver.cfg"
          export NETSERVER

    # __DB Names________________________________________________
       TORONTODB="${TORONTOPWD}/TorontoDB"
          export TORONTODB
       NEWYORKDB="${NEWYORKPWD}/NewYorkDB"
          export NEWYORKDB
       BROOKLYNDB="${BROOKLYNPWD}/BrooklynDB"
          export BROOKLYNDB
       TOKYODB="${TOKYOPWD}/TokyoDB"
          export TOKYODB

    # __Table Names______________________________________________
       TORONTOPLIST=TorontoPList
          export TORONTOPLIST
       NEWYORKPLIST=NewYorkPList
          export NEWYORKPLIST
       BROOKLYNPLIST=BrooklynPList
          export BROOKLYNPLIST
       TOKYOPLIST=TokyoPList
          export TOKYOPLIST

    # __Access Information__________________________________________
    # These variables are to simplify typing the access information to
    # Replication Maste and Replication Replicates.
    #
       TORONTO_RM_INFO="'${TORONTOREPSERVER}':'${TORONTODB}':${TORONTOPLIST}"
          export TORONTO_RM_INFO
       NEWYORK_RR_INFO="'${NEWYORKHOST}':'${NEWYORKDB}':${NEWYORKPLIST}"
          export NEWYORK_RR_INFO
       NEWYORK_RM_INFO="'${NEWYORKREPSERVER}':'${NEWYORKDB}':${NEWYORKPLIST}"
          export NEWYORK_RM_INFO
       BROOKLYN_RR_INFO="'${BROOKLYNHOST}':'${BROOKLYNDB}':${BROOKLYNPLIST}"
          export BROOKLYN_RR_INFO
       TOKYO_RR_INFO="'${TOKYOHOST}':'${TOKYODB}':${TOKYOPLIST}"
          export TOKYO_RR_INFO

    # --------------------------------------------------
    # Scenario D
    # --------------------------------------------------

    #
    # Presteps:
    #
    # " ${TORONTOHOST}: OpB1.1. Create Database ${TORONTODB}"
       empmkdb ${TORONTODB}

    # "$TORONTODB: OpB1.2. create table ${TORONTOPLIST}"
    empbatch ${TORONTODB} << @
       create ${TORONTOPLIST} (\
             prod_id integer not null,  \
             prod_name character(30,1) not null, \
             prod_price float,\
             prod_lang character(15,1));
    @

    # "$TORONTODB: OpB1.3. insert data into ${TORONTOPLIST}"
    empbatch ${TORONTODB} << @
       insert into ${TORONTOPLIST} values (1, 'DB1', 4000, 'english');
       insert into ${TORONTOPLIST} values (3, 'DB2', 7000, 'english');
    @

    # "$NEWYORKHOST:  OpB1.4. Create database ${NEWYORKDB}"
       empmkdb ${NEWYORKDB}

    # "------------------- OpB1 ------------------------------------"

    # "${TORONTODB}: OpB1. Define master table [${TORONTOPLIST}] "
    empbatch ${TORONTODB} << @
       alter ${TORONTOPLIST} change table type to MASTER;
    @

    # "------------------- OpB2 ------------------------------------"

    # "${TORONTOHOST}: OpB2. Configure Network Server on RMT Side [${TORONTOREPSERVER}] "

    # "OpB2.1 Network Server Config File"
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVER} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpB3 ------------------------------------"

    # "OpB3. Start Replication Master Server ${TORONTOREPSERVER}"
       empsvadm ${TORONTOREPSERVER} start

    # "------------------- OpB4 ------------------------------------"

    # "${TORONTODB}: OpB4.
    #  Create Replication Replicate [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    empbatch ${TORONTODB} << @
       create replication replicate \
         ${NEWYORK_RR_INFO} \
         ON ${TORONTOPLIST};
    @

    # "------------------- OpB5 ------------------------------------"

    # Steps of OpB5 are to be executed if ${NEWYORKHOST} and ${TORONTOHOST} are
    # different. Otherwise, these is no need to create the files once more.

    # "${NEWYORKHOST}: OpB5.  Configure Network Server on RRT Side [${NEWYORKPLIST}] "
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVER} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpB6 ------------------------------------"

    # "${NEWYORKDB}: OpB6. Create Replicate Table and Load Data [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    empbatch ${NEWYORKDB} << @
       create and insert into replicate table \
            ${NEWYORKPLIST}  \
            FROM ${TORONTO_RM_INFO};
    @

    # "------------------- OpB7 ------------------------------------"
    #
    # ${NEWYORKHOST}: OpB7. Configure Network Server on RMT Side (NewYorkRepServer)
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat >>  ${NETSERVER} << @
    MSNETSERVER
        NAME=${NEWYORKREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${NEWYORKHOST}
        PORT_ADMIN=12350
        PORT_SERVICE=12355
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpB8 ------------------------------------"
    #
    # ${NEWYORKHOST}: OpB8. Start Replication Master Server (NewYorkRepServer)
       empsvadm ${NEWYORKREPSERVER} start

    # "------------------- OpB9 ------------------------------------"
    # ${NEWYORKDB}: OpB9. Create Replication Replicate (${BROOKLYNPLIST}, ${NEWYORKPLIST})
    empbatch ${NEWYORKDB} << @
       create replication replicate \
            ${BROOKLYN_RR_INFO} \
            ON ${NEWYORKPLIST};
    @

    # "------------------- OpB10 ------------------------------------"
    # ${BROOKLYNHOST}: OpB10.  Configure Network Server on RRT Side [${BROOKLYNPLIST}]

    # *******************  ATTENTION: **********************************
    # Execute OpB10 only if ${NEWYORKHOST} is different from ${BROOKLYNHOST}
    # ******************************************************************

    # "OpB10.1 Network Server Config File"
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat >> ${NETSERVER} << @
    MSNETSERVER
        NAME=${NEWYORKREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${NEWYORKHOST}
        PORT_ADMIN=12350
        PORT_SERVICE=12355
    MSNETSERVEREND
    @

    # Pre-step 11.1: Create database ${BROOKLYNDB}
       empmkdb ${BROOKLYNDB}

    # "------------------- OpB11 ------------------------------------"
    # ${BROOKLYNDB}: OpB11. Create Replicate Table (${BROOKLYNPLIST}, ${NEWYORKPLIST})
    empbatch ${BROOKLYNDB} << @
       create and insert into replicate table \
           ${BROOKLYNPLIST} \
           FROM ${NEWYORK_RM_INFO}";
    @

    # "------------------- OpC1  ------------------------------------"
    #
    # TORONTODB: OpC1. Create Replication Replicate (BROOKLYNPLIST, TORONTOPLIST)
    empbatch ${TORONTODB} << @
       CREATE REPLICATION REPLICATE \
           ${BROOKLYN_RR_INFO}  \
           ON ${TORONTOPLIST};
    @

    # "------------------- OpC2 ------------------------------------"
    # "${BROOKLYNHOST}: OpC2.  Configure Network Server on RRT Side [${BROOKLYNPLIST}] "
    # Execute step C2 only if ${TORONTOHOST} is different from ${BROOKLYNHOST}
    #

    # "OpC2.1 Network Server Config File"
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat >> ${NETSERVER} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpC3  ------------------------------------"
    #
    # $BrooklynDB: OpC3. Create Replication Master (${TORONTOPLIST}, ${BROOKLYNPLIST})
    empbatch  ${BROOKLYNDB} << @
       CREATE REPLICATION MASTER \
          ${TORONTO_RM_INFO} \
           ON ${BROOKLYNPLIST};
    @

    # "------------------- OpC4 ------------------------------------"
    #
    # "${BROOKLYNDB}: OpC4. View Replication Table and Synch Status [${BROOKLYNPLIST}] "
    empbatch ${BROOKLYNDB} << @
       display table ${BROOKLYNPLIST} all;
    @

    # "Check the contents of the Replication Replicate Table ${BROOKLYNPLIST}"
    empbatch ${BROOKLYNDB} << @
       select * from ${BROOKLYNPLIST};
    @

    # "------------------- OpD1 ------------------------------------"

    # $BrooklynDB: OpD1. Change the Replication Master Order [BrooklynPList, order]
    empbatch ${BROOKLYNDB} << @
       ALTER TABLE ${BROOKLYNPLIST} \
          CHANGE REPLICATION MASTER ORDER \
          ${NEWYORK_RM_INFO} 4, ${TORONTO_RM_INFO} 3;
    @

    # "------------------- OpD2 ------------------------------------"

    # "${BROOKLYNHOST}: OpD2. Perform a Synchronization [${BROOKLYNPLIST}]"
       emprepsync -v ${BROOKLYNDB} ${BROOKLYNPLIST}

    # "------------------- OpD3 ------------------------------------"

    # "${BROOKLYNDB}: OpD3. View Replication Table and Synch Status [${BROOKLYNPLIST}] "
    empbatch ${BROOKLYNDB} << @
       display table ${BROOKLYNPLIST} all;
    @

    # "Check the contents of the Replication Replicate Table ${BROOKLYNPLIST}"
    empbatch ${BROOKLYNDB} << @
       select * from ${BROOKLYNPLIST};
    @

### B.5.2 Other possible operations in scenario D

    # "------------------------------------------------------------"
    # "the rest of the commands undo the effects of Scenario 1"
    # "------------------------------------------------------------"

    # $BrooklynDB: Unclaim Replication Master (${BROOKLYNPLIST}, ${TORONTOPLIST})
    #  empcmd  ${BROOKLYNDB}  "DROP REPLICATION MASTER \
    #      ${TORONTO_RM_INFO} \
    #       ON ${BROOKLYNPLIST};"

    # "${TORONTODB}: Unauthorize Replication Replicate [${TORONTOPLIST}, ${BROOKLYNPLIST}] "
    #   empcmd ${TORONTODB} "DROP REPLICATION REPLICATE \
    #         ${BROOKLYN_RR_INFO} \
    #         ON ${TORONTOPLIST};"

    # "${BROOKLYNDB}: Drop Replicate Table [${BROOKLYNPLIST}] "
    #   empcmd ${BROOKLYNDB} "DROP TABLE ${BROOKLYNPLIST};"

    # "${TORONTODB}: Unauthorize Replication Replicate [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    #   empcmd ${TORONTODB} "DROP REPLICATION REPLICATE \
    #         ${NEWYORK_RR_INFO} \
    #          ON ${TORONTOPLIST};"

    # "${TORONTOHOST}: Stop Replication Master Server [${TORONTOREPSERVER}]"
    #   empsvadm ${TORONTOREPSERVER} stop

    # "${TORONTODB}:  Undefine Master Table [${TORONTOPLIST}]"
    #   empcmd ${TORONTODB} "ALTER TABLE ${TORONTOPLIST} CHANGE TABLE TYPE TO NORMAL;"

    #---------------------------------------------------------------
    # "Post Steps to completely clear the effects"

    # "Remove database ${NEWYORKDB}"
    #   emprmdb ${NEWYORKDB}
    # "Remove database ${TORONTODB}"
    #   emprmdb ${TORONTODB}
    # "Remove database ${BROOKLYNDB}
    #   emprmdb ${BROOKLYNDB}
    # "remove server log file"
    #   rm ${TORONTOREPSERVER}.log

## B.6 Scenario E

### B.6.1 Operations for Creating the Scenario E

    #!/bin/sh

    # Set the following variables to their appropriate values:
    # Directories, Host Names, Replication Master Server Names

    # ___Directories_______________________
    # Set these variables to the path of the database directory
    # Their default value is the current directory.
    # For example if Database directory for TorontoDB is
    # "/usr/empress/data/TorontoDB", then TORONTOPWD must be set to
    # "/usr/empress/data"
    #
       TORONTOPWD=`pwd`
          export TORONTOPWD
       NEWYORKPWD=`pwd`
          export NEWYORKPWD
       BROOKLYNPWD=`pwd`
          export BROOKLYNPWD
       TOKYOPWD=`pwd`
          export TOKYOPWD

    # __Host Names_____________________________________________
    # These will contain the network address and host names of their corresponding
    # hosts. Their default is localhost
    # For example if the host that TorontoDB will reside is "toronto.empress.com",
    # then TORONTOHOST must be set to "toronto.empress.com" (or to "toronto" if
    # all the databases are using the same network domain).
    #
       TORONTOHOST=`hostname`
          export TORONTOHOST
       NEWYORKHOST=`hostname`
          export NEWYORKHOST
       BROOKLYNHOST=`hostname`
          export BROOKLYNHOST
       TOKYOHOST=`hostname`
          export TOKYOHOST

    # __Replication Master Servers___________
    # Name of the Replication Master Servers
    #
       TORONTOREPSERVER=TorontoRepServer
          export TORONTOREPSERVER
       NEWYORKREPSERVER=NewYorkRepServer
          export NEWYORKREPSERVER

    # ___Others____________________________
    #
       SERVERTYPE=replication_master
          export SERVERTYPE
       NETSERVER="${HOME}/.empress/netserver.cfg"
          export NETSERVER

    # __DB Names________________________________________________
       TORONTODB="${TORONTOPWD}/TorontoDB"
          export TORONTODB
       NEWYORKDB="${NEWYORKPWD}/NewYorkDB"
          export NEWYORKDB
       BROOKLYNDB="${BROOKLYNPWD}/BrooklynDB"
          export BROOKLYNDB
       TOKYODB="${TOKYOPWD}/TokyoDB"
          export TOKYODB

    # __Table Names______________________________________________
       TORONTOPLIST=TorontoPList
          export TORONTOPLIST
       NEWYORKPLIST=NewYorkPList
          export NEWYORKPLIST
       BROOKLYNPLIST=BrooklynPList
          export BROOKLYNPLIST
       TOKYOPLIST=TokyoPList
          export TOKYOPLIST

    # __Access Information__________________________________________
    # These variables are to simplify typing the access information to
    # Replication Maste and Replication Replicates.
    #
       TORONTO_RM_INFO="'${TORONTOREPSERVER}':'${TORONTODB}':${TORONTOPLIST}"
          export TORONTO_RM_INFO
       NEWYORK_RR_INFO="'${NEWYORKHOST}':'${NEWYORKDB}':${NEWYORKPLIST}"
          export NEWYORK_RR_INFO
       NEWYORK_RM_INFO="'${NEWYORKREPSERVER}':'${NEWYORKDB}':${NEWYORKPLIST}"
          export NEWYORK_RM_INFO
       BROOKLYN_RR_INFO="'${BROOKLYNHOST}':'${BROOKLYNDB}':${BROOKLYNPLIST}"
          export BROOKLYN_RR_INFO
       TOKYO_RR_INFO="'${TOKYOHOST}':'${TOKYODB}':${TOKYOPLIST}"
          export TOKYO_RR_INFO

    # --------------------------------------------------
    # Scenario E
    # --------------------------------------------------

    #
    # Presteps:
    #
    # " ${TORONTOHOST}: OpB1.1. Create Database ${TORONTODB}"
       empmkdb ${TORONTODB}

    # "$TORONTODB: OpB1.2. create table ${TORONTOPLIST}"
    empbatch ${TORONTODB} << @
       create ${TORONTOPLIST} (\
             prod_id integer not null,  \
             prod_name character(30,1) not null, \
             prod_price float,\
             prod_lang character(15,1));
    @

    # "$TORONTODB: OpB1.3. insert data into ${TORONTOPLIST}"
    empbatch ${TORONTODB} << @
       insert into ${TORONTOPLIST} values (1, 'DB1', 4000, 'english');
       insert into ${TORONTOPLIST} values (3, 'DB2', 7000, 'english');
    @

    # "$NEWYORKHOST:  OpB1.4. Create database ${NEWYORKDB}"
       empmkdb ${NEWYORKDB}

    # "------------------- OpB1 ------------------------------------"

    # "${TORONTODB}: OpB1. Define master table [${TORONTOPLIST}] "
    empbatch ${TORONTODB} << @
       alter ${TORONTOPLIST} change table type to MASTER;
    @

    # "------------------- OpB2 ------------------------------------"

    # "${TORONTOHOST}: OpB2. Configure Network Server on RMT Side [${TORONTOREPSERVER}] "

    # "OpB2.1 Network Server Config File"
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVER} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpB3 ------------------------------------"

    # "OpB3. Start Replication Master Server ${TORONTOREPSERVER}"
       empsvadm ${TORONTOREPSERVER} start

    # "------------------- OpB4 ------------------------------------"

    # "${TORONTODB}: OpB4.
    #  Create Replication Replicate [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    empbatch ${TORONTODB} << @
       create replication replicate \
         ${NEWYORK_RR_INFO} \
         ON ${TORONTOPLIST};
    @

    # "------------------- OpB5 ------------------------------------"

    # Steps of OpB5 are to be executed if ${NEWYORKHOST} and ${TORONTOHOST} are
    # different. Otherwise, these is no need to create the files once more.

    # "${NEWYORKHOST}: OpB5.  Configure Network Server on RRT Side [${NEWYORKPLIST}] "
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVER} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpB6 ------------------------------------"

    # "${NEWYORKDB}: OpB6. Create Replicate Table and Load Data [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    empbatch ${NEWYORKDB} << @
       create and insert into replicate table \
            ${NEWYORKPLIST}  \
            FROM ${TORONTO_RM_INFO};
    @

    # "------------------- OpB7 ------------------------------------"
    #
    # ${NEWYORKHOST}: OpB7. Configure Network Server on RMT Side (NewYorkRepServer)
    # "OpB7.1 Network Server Config File"
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat >>  ${NETSERVER} << @
    MSNETSERVER
        NAME=${NEWYORKREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${NEWYORKHOST}
        PORT_ADMIN=12350
        PORT_SERVICE=12355
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpB8 ------------------------------------"
    #
    # ${NEWYORKHOST}: OpB8. Start Replication Master Server (NewYorkRepServer)
       empsvadm ${NEWYORKREPSERVER} start

    # "------------------- OpB9 ------------------------------------"
    # ${NEWYORKDB}: OpB9. Create Replication Replicate (${BROOKLYNPLIST}, ${NEWYORKPLIST})
    empbatch ${NEWYORKDB} << @
       create replication replicate \
            ${BROOKLYN_RR_INFO} \
            ON ${NEWYORKPLIST};
    @

    # "------------------- OpB10 ------------------------------------"
    # ${BROOKLYNHOST}: OpB10.  Configure Network Server on RRT Side [${BROOKLYNPLIST}]

    # *******************  ATTENTION: **********************************
    # Execute OpB10 only if ${NEWYORKHOST} is different from ${BROOKLYNHOST}
    # ******************************************************************

    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVER} << @
    MSNETSERVER
        NAME=${NEWYORKREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${NEWYORKHOST}
        PORT_ADMIN=12350
        PORT_SERVICE=12355
    MSNETSERVEREND
    @

    # Pre-step 11.1: Create database ${BROOKLYNDB}
       empmkdb ${BROOKLYNDB}

    # "------------------- OpB11 ------------------------------------"
    # ${BROOKLYNDB}: OpB11. Create Replicate Table (${BROOKLYNPLIST}, ${NEWYORKPLIST})
    empbatch ${BROOKLYNDB} << @
       create and insert into replicate table \
           ${BROOKLYNPLIST} \
           FROM ${NEWYORK_RM_INFO};
    @

    # "------------------- OpC1  ------------------------------------"
    #
    # TORONTODB: OpC1. Create Replication Replicate (BROOKLYNPLIST, TORONTOPLIST)
    empbatch ${TORONTODB} << @
       CREATE REPLICATION REPLICATE \
           ${BROOKLYN_RR_INFO}  \
           ON ${TORONTOPLIST};
    @

    # "------------------- OpC2 ------------------------------------"
    # "${BROOKLYNHOST}: OpC2.  Configure Network Server on RRT Side [${BROOKLYNPLIST}] "
    # Execute step C2 only if ${TORONTOHOST} is different from ${BROOKLYNHOST}
    #

    # "OpC2.1 Network Server Config File"
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat >> ${NETSERVER} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpC3  ------------------------------------"
    #
    # $BrooklynDB: OpC3. Create Replication Master (${TORONTOPLIST}, ${BROOKLYNPLIST})
       empcmd  ${BROOKLYNDB} "CREATE REPLICATION MASTER \
          ${TORONTO_RM_INFO} \
           ON ${BROOKLYNPLIST};"

    # "------------------- OpC4 ------------------------------------"
    #
    # "${BROOKLYNDB}: OpC4. View Replication Table and Synch Status [${BROOKLYNPLIST}] "
    empbatch ${BROOKLYNDB} << @
       display table ${BROOKLYNPLIST} all;
    @

    # "Check the contents of the Replication Replicate Table ${BROOKLYNPLIST}"
    empbatch ${BROOKLYNDB} << @
       select * from ${BROOKLYNPLIST};
    @

    # "------------------- OpD1 ------------------------------------"

    # $BrooklynDB: OpD1. Change the Replication Master Order [BrooklynPList, order]
    empbatch ${BROOKLYNDB} << @
       ALTER TABLE ${BROOKLYNPLIST} \
          CHANGE REPLICATION MASTER ORDER \
          ${NEWYORK_RM_INFO} 4, ${TORONTO_RM_INFO} 3;
    @

    # "------------------- OpE1 ------------------------------------"
    #
    # $BrooklynDB: OpE1. Disable the Replication Master (BrooklynPList, TorontoPList)
    empbatch ${BROOKLYNDB} << @
       ALTER TABLE ${BROOKLYNPLIST}
          DISABLE REPLICATION MASTER ${TORONTO_RM_INFO};
    @

    # "------------------- OpE3 ------------------------------------"
    #
    # "${BROOKLYNHOST}: OpE3. Perform a Synchronization [${BROOKLYNPLIST}]"
       emprepsync -v ${BROOKLYNDB} ${BROOKLYNPLIST}

    # "------------------- OpE4 ------------------------------------"
    #
    # "${BROOKLYNDB}: OpE4. View Replication Table and Synchronization Status [${BROOKLYNPLIST}] "
    empbatch ${BROOKLYNDB} << @
       display table ${BROOKLYNPLIST} all;
    @

    # "Check the contents of the Replication Replicate Table ${BROOKLYNPLIST}"
    empbatch ${BROOKLYNDB} << @
       select * from ${BROOKLYNPLIST};
    @

### B.6.2 Other possible operations in scenario E

    # "------------------- OpE2 ------------------------------------"

    # $BrooklynDB: OpE2. Enable the Replication Master (BrooklynPList, TorontoPList)
    empbatch ${BROOKLYNDB} << @
       ALTER TABLE ${BROOKLYNPLIST}
          ENABLE REPLICATION MASTER ${TORONTO_RM_INFO};
    @

## B.7 Scenario F

### B.7.1 Operations for Creating the Scenario F

    #!/bin/sh

    # Set the following variables to their appropriate values:
    # Directories, Host Names, Replication Master Server Names

    # ___Directories_______________________
    # Set these variables to the path of the database directory
    # Their default value is the current directory.
    # For example if Database directory for TorontoDB is
    # "/usr/empress/data/TorontoDB", then TORONTOPWD must be set to
    # "/usr/empress/data"
    #
       TORONTOPWD=`pwd`
          export TORONTOPWD
       NEWYORKPWD=`pwd`
          export NEWYORKPWD
       BROOKLYNPWD=`pwd`
          export BROOKLYNPWD
       TOKYOPWD=`pwd`
          export TOKYOPWD

    # __Host Names_____________________________________________
    # These will contain the network address and host names of their corresponding
    # hosts. Their default is localhost
    # For example if the host that TorontoDB will reside is "toronto.empress.com",
    # then TORONTOHOST must be set to "toronto.empress.com" (or to "toronto" if
    # all the databases are using the same network domain).
    #
       TORONTOHOST=`hostname`
          export TORONTOHOST
       NEWYORKHOST=`hostname`
          export NEWYORKHOST
       BROOKLYNHOST=`hostname`
          export BROOKLYNHOST
       TOKYOHOST=`hostname`
          export TOKYOHOST

    # __Replication Master Servers___________
    # Name of the Replication Master Servers
    #
       TORONTOREPSERVER=TorontoRepServer
          export TORONTOREPSERVER
       NEWYORKREPSERVER=NewYorkRepServer
          export NEWYORKREPSERVER

    # ___Others____________________________
    #
       SERVERTYPE=replication_master
          export SERVERTYPE
       NETSERVER="${HOME}/.empress/netserver.cfg"
          export NETSERVER

    # __DB Names________________________________________________
       TORONTODB="${TORONTOPWD}/TorontoDB"
          export TORONTODB
       NEWYORKDB="${NEWYORKPWD}/NewYorkDB"
          export NEWYORKDB
       BROOKLYNDB="${BROOKLYNPWD}/BrooklynDB"
          export BROOKLYNDB
       TOKYODB="${TOKYOPWD}/TokyoDB"
          export TOKYODB

    # __Table Names______________________________________________
       TORONTOPLIST=TorontoPList
          export TORONTOPLIST
       NEWYORKPLIST=NewYorkPList
          export NEWYORKPLIST
       BROOKLYNPLIST=BrooklynPList
          export BROOKLYNPLIST
       TOKYOPLIST=TokyoPList
          export TOKYOPLIST

    # __Access Information__________________________________________
    # These variables are to simplify typing the access information to
    # Replication Maste and Replication Replicates.
    #
       TORONTO_RM_INFO="'${TORONTOREPSERVER}':'${TORONTODB}':${TORONTOPLIST}"
          export TORONTO_RM_INFO
       NEWYORK_RR_INFO="'${NEWYORKHOST}':'${NEWYORKDB}':${NEWYORKPLIST}"
          export NEWYORK_RR_INFO
       NEWYORK_RM_INFO="'${NEWYORKREPSERVER}':'${NEWYORKDB}':${NEWYORKPLIST}"
          export NEWYORK_RM_INFO
       BROOKLYN_RR_INFO="'${BROOKLYNHOST}':'${BROOKLYNDB}':${BROOKLYNPLIST}"
          export BROOKLYN_RR_INFO
       TOKYO_RR_INFO="'${TOKYOHOST}':'${TOKYODB}':${TOKYOPLIST}"
          export TOKYO_RR_INFO

    # --------------------------------------------------
    # Scenario F
    # --------------------------------------------------

    #
    # Presteps:
    #
    # " ${TORONTOHOST}: OpB1.1. Create Database ${TORONTODB}"
       empmkdb ${TORONTODB}

    # "$TORONTODB: OpB1.2. create table ${TORONTOPLIST}"
    empbatch ${TORONTODB} << @
       create ${TORONTOPLIST} (\
             prod_id integer not null,  \
             prod_name character(30,1) not null, \
             prod_price float,\
             prod_lang character(15,1));
    @

    # "$TORONTODB: OpB1.3. insert data into ${TORONTOPLIST}"
    empbatch ${TORONTODB} << @
       insert into ${TORONTOPLIST} values (1, 'DB1', 4000, 'english');
       insert into ${TORONTOPLIST} values (3, 'DB2', 7000, 'english');
    @

    # "$NEWYORKHOST:  OpB1.4. Create database ${NEWYORKDB}"
       empmkdb ${NEWYORKDB}

    # "------------------- OpB1 ------------------------------------"

    # "${TORONTODB}: OpB1. Define master table [${TORONTOPLIST}] "
    empbatch ${TORONTODB} << @
       alter ${TORONTOPLIST} change table type to MASTER;
    @

    # "------------------- OpB2 ------------------------------------"

    # "${TORONTOHOST}: OpB2. Configure Network Server on RMT Side [${TORONTOREPSERVER}] "

    # "OpB2.1 Network Server Config File"
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVER} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpB3 ------------------------------------"

    # "OpB3. Start Replication Master Server ${TORONTOREPSERVER}"
       empsvadm ${TORONTOREPSERVER} start

    # "------------------- OpB4 ------------------------------------"

    # "${TORONTODB}: OpB4.
    #  Create Replication Replicate [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    empbatch ${TORONTODB} << @
       create replication replicate \
         ${NEWYORK_RR_INFO} \
         ON ${TORONTOPLIST};
    @

    # "------------------- OpB5 ------------------------------------"

    # Steps of OpB5 are to be executed if ${NEWYORKHOST} and ${TORONTOHOST} are
    # different. Otherwise, these is no need to create the files once more.

    # "${NEWYORKHOST}: OpB5.  Configure Network Server on RRT Side [${NEWYORKPLIST}] "
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVER} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpB6 ------------------------------------"

    # "${NEWYORKDB}: OpB6. Create Replicate Table and Load Data [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    empbatch ${NEWYORKDB} << @
       create and insert into replicate table \
            ${NEWYORKPLIST}  \
            FROM ${TORONTO_RM_INFO};
    @

    # "------------------- OpB7 ------------------------------------"
    #
    # ${NEWYORKHOST}: OpB7. Configure Network Server on RMT Side (NewYorkRepServer)
    # "OpB7.1 Network Server Config File"
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat >>  ${NETSERVER} << @
    MSNETSERVER
        NAME=${NEWYORKREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${NEWYORKHOST}
        PORT_ADMIN=12350
        PORT_SERVICE=12355
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpB8 ------------------------------------"
    #
    # ${NEWYORKHOST}: OpB8. Start Replication Master Server (NewYorkRepServer)
       empsvadm ${NEWYORKREPSERVER} start

    # "------------------- OpB9 ------------------------------------"
    # ${NEWYORKDB}: OpB9. Create Replication Replicate (${BROOKLYNPLIST}, ${NEWYORKPLIST})
    empbatch ${NEWYORKDB} << @
       create replication replicate \
            ${BROOKLYN_RR_INFO} \
            ON ${NEWYORKPLIST};
    @

    # "------------------- OpB10 ------------------------------------"
    # ${BROOKLYNHOST}: OpB10.  Configure Network Server on RRT Side [${BROOKLYNPLIST}]

    # *******************  ATTENTION: **********************************
    # Execute OpB10 only if ${NEWYORKHOST} is different from ${BROOKLYNHOST}
    # ******************************************************************

    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVER} << @
    MSNETSERVER
        NAME=${NEWYORKREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${NEWYORKHOST}
        PORT_ADMIN=12350
        PORT_SERVICE=12355
    MSNETSERVEREND
    @

    # Pre-step 11.1: Create database ${BROOKLYNDB}
       empmkdb ${BROOKLYNDB}

    # "------------------- OpB11 ------------------------------------"
    # ${BROOKLYNDB}: OpB11. Create Replicate Table (${BROOKLYNPLIST}, ${NEWYORKPLIST})
    empbatch ${BROOKLYNDB} << @
       create and insert into replicate table \
           ${BROOKLYNPLIST} \
           FROM ${NEWYORK_RM_INFO};
    @

    # "------------------- OpF1 ------------------------------------"
    #
    # "${NEWYORKDB}: OpF1. Define master table [${NEWYORKPLIST}] "
    empbatch ${NEWYORKDB} << @
       alter ${NEWYORKPLIST} change table type to MASTER;
    @

### B.7.2 Other possible operations in scenario F

    # "------------------- OpF2 ------------------------------------"
    #
    # NewYorkDB: OpF2. Create Replication Replicate (TorontoPList, NewYorkPList)
      empcmd ${NEWYORKDB} "CREATE REPLICATION REPLICATE ${TORONTO_RR_INFO} ON ${NEWYORKPLIST};"

    # TorontoDB: OpF3. Create Replication Master (TorontoPList, BrooklynPList)
      empcmd ${TORONTODB} "CREATE REPLICATION MASTER ${NEWYORK_RM_INFO} ON ${TORONTOPLIST};"

    # TorontoDB: OpF4. Change Table type to Replicate (NewYorkPList)
    empbatch ${TORONTODB} << @
       ALTER TABLE ${TORONTOPLIST} CHANGE TABLE TYPE TO REPLICATE;
    @

    # TorontoHost: OpF5. Perform a Synchronization (TorontoPList)
      emprepsync ${TORONTODB} ${TORONTOPLIST}

    # TorontoDB: OpF6. Change Table type to Master (TorontoPList)
      empcmd ${TORONTODB} "ALTER TABLE ${TORONTOPLIST} CHANGE TABLE TYPE TO MASTER;"

    # NewYorkDB: OpF7. Change Table type to Replicate (NewYorkPList)
      empcmd ${NEWYORKDB} "ALTER TABLE ${NEWYORKPLIST} CHANGE TABLE TYPE TO REPLICATE;

    # "${BROOKLYNDB}: Drop Replicate Table [${BROOKLYNPLIST}] "
    # empcmd ${BROOKLYNDB} "DROP TABLE ${BROOKLYNPLIST};"

    # "${TORONTODB}:  Unauthorize Replication Replicate [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    #   empcmd ${TORONTODB} "DROP REPLICATION REPLICATE \
    #         ${NEWYORK_RR_INFO} \
    #          ON ${TORONTOPLIST};"

    # "${TORONTOHOST}: Stop Replication Master Server [${TORONTOREPSERVER}]"
    #   empsvadm ${TORONTOREPSERVER} stop

    # "${TORONTODB}: Undefine Master Table [${TORONTOPLIST}]"
    #   empcmd ${TORONTODB} "ALTER TABLE ${TORONTOPLIST} CHANGE TABLE TYPE TO NORMAL;"

    #---------------------------------------------------------------
    # "Post Steps to completely clear the effects"

    # "Remove database ${NEWYORKDB}"
    #   emprmdb ${NEWYORKDB}
    # "Remove database ${TORONTODB}"
    #   emprmdb ${TORONTODB}
    # "Remove database ${BROOKLYNDB}
    #   emprmdb ${BROOKLYNDB}
    # "remove server log file"
    #   rm ${TORONTOREPSERVER}.log

## B.8 Scenario G

### B.8.1 Operations for Creating the Scenario G

    #!/bin/sh

    # Set the following variables to their appropriate values:
    # Directories, Host Names, Replication Master Server Names

    # ___Directories_______________________
    # Set these variables to the path of the database directory
    # Their default value is the current directory.
    # For example if Database directory for TorontoDB is
    # "/usr/empress/data/TorontoDB", then TORONTOPWD must be set to
    # "/usr/empress/data"
    #
       TORONTOPWD=`pwd`
          export TORONTOPWD
       NEWYORKPWD=`pwd`
          export NEWYORKPWD
       BROOKLYNPWD=`pwd`
          export BROOKLYNPWD
       TOKYOPWD=`pwd`
          export TOKYOPWD

    # __Host Names_____________________________________________
    # These will contain the network address and host names of their corresponding
    # hosts. Their default is localhost
    # For example if the host that TorontoDB will reside is "toronto.empress.com",
    # then TORONTOHOST must be set to "toronto.empress.com" (or to "toronto" if
    # all the databases are using the same network domain).
    #
       TORONTOHOST=`hostname`
          export TORONTOHOST
       NEWYORKHOST=`hostname`
          export NEWYORKHOST
       BROOKLYNHOST=`hostname`
          export BROOKLYNHOST
       TOKYOHOST=`hostname`
          export TOKYOHOST

    # __Replication Master Servers___________
    # Name of the Replication Master Servers
    #
       TORONTOREPSERVER=TorontoRepServer
          export TORONTOREPSERVER
       NEWYORKREPSERVER=NewYorkRepServer
          export NEWYORKREPSERVER

    # ___Others____________________________
    #
       SERVERTYPE=replication_master
          export SERVERTYPE
       NETSERVER="${HOME}/.empress/netserver.cfg"
          export NETSERVER

    # __DB Names________________________________________________
       TORONTODB="${TORONTOPWD}/TorontoDB"
          export TORONTODB
       NEWYORKDB="${NEWYORKPWD}/NewYorkDB"
          export NEWYORKDB
       BROOKLYNDB="${BROOKLYNPWD}/BrooklynDB"
          export BROOKLYNDB
       TOKYODB="${TOKYOPWD}/TokyoDB"
          export TOKYODB

    # __Table Names______________________________________________
       TORONTOPLIST=TorontoPList
          export TORONTOPLIST
       NEWYORKPLIST=NewYorkPList
          export NEWYORKPLIST
       BROOKLYNPLIST=BrooklynPList
          export BROOKLYNPLIST
       TOKYOPLIST=TokyoPList
          export TOKYOPLIST

    # __Access Information__________________________________________
    # These variables are to simplify typing the access information to
    # Replication Maste and Replication Replicates.
    #
       TORONTO_RM_INFO="'${TORONTOREPSERVER}':'${TORONTODB}':${TORONTOPLIST}"
          export TORONTO_RM_INFO
       NEWYORK_RR_INFO="'${NEWYORKHOST}':'${NEWYORKDB}':${NEWYORKPLIST}"
          export NEWYORK_RR_INFO
       NEWYORK_RM_INFO="'${NEWYORKREPSERVER}':'${NEWYORKDB}':${NEWYORKPLIST}"
          export NEWYORK_RM_INFO
       BROOKLYN_RR_INFO="'${BROOKLYNHOST}':'${BROOKLYNDB}':${BROOKLYNPLIST}"
          export BROOKLYN_RR_INFO
       TOKYO_RR_INFO="'${TOKYOHOST}':'${TOKYODB}':${TOKYOPLIST}"
          export TOKYO_RR_INFO

    # --------------------------------------------------
    # Scenario G
    # --------------------------------------------------

    # Pre-Steps:
    #
    # " ${TORONTOHOST}: OpG1.1: Create Database ${TORONTODB}"
       empmkdb ${TORONTODB}

    # "$TORONTODB: OpG1.2: create table ${TORONTOPLIST}"
    empbatch ${TORONTODB} << @
       create ${TORONTOPLIST} (\
             prod_id integer not null,  \
             prod_name character(30,1) not null, \
             prod_price float,\
             prod_lang character(15,1));
    @

    # "$TORONTODB: OpG1.3: Create Primary Key for ${TORONTOPLIST}"
    empbatch ${TORONTODB} << @
       alter table ${TORONTOPLIST} add primary key on (prod_id);
    @

    # "$TORONTODB: OpG1.4: insert data into ${TORONTOPLIST}"
    empbatch ${TORONTODB} << @
       insert into ${TORONTOPLIST} values (1, 'DB1', 4000, 'english');
       insert into ${TORONTOPLIST} values (3, 'DB2', 7000, 'english');
       insert into ${TORONTOPLIST} values (2, 'DB1', 5000, 'japanese');
       insert into ${TORONTOPLIST} values (4, 'DB2', 7500, 'japanese');
    @

    # "$NEWYORKHOST:  OpG1.5 Create database ${NEWYORKDB}"
       empmkdb ${NEWYORKDB}

    # "$TOKYOHOST:  OpG1.6 Create database ${TOKYODB}"
       empmkdb ${TOKYODB}

    # "------------------- OpG1 ------------------------------------"

    # $TorontoDB: OpG1. Establish Master Table with Subset attribute Group (TorontoPList, SAG)
    empbatch ${TORONTODB} << @
       ALTER TABLE ${TORONTOPLIST} CHANGE TABLE TYPE TO MASTER FOR SUBSET ON (prod_lang);
    @

    # "------------------- OpG2 ------------------------------------"
    #
    # $TORONTOHOST}: OpG2. Configure Network Server on RMT Side [${TORONTOREPSERVER}]
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > $NETSERVER << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpG3 ------------------------------------"
    #
    # "OpG3. Start Replication Master Server ${TORONTOREPSERVER}"
       empsvadm ${TORONTOREPSERVER} start

    # "------------------- OpG4 ------------------------------------"

    #TorontoDB: OpG4. Create Replication Replicate with Selected Rows
    #      (TorontoPList, NewYorkPList, "RSWC_english_products")
    empbatch ${TORONTODB} << @
       CREATE REPLICATION REPLICATE
          ${NEWYORK_RR_INFO}
          ON ${TORONTOPLIST} WHERE prod_lang = 'english';
    @

    # "------------------- OpG5 ------------------------------------"
    #
    # TorontoDB: OpG5. Create Replication Replicate with Selected Rows
    #   (TorontoPList, TokyoPList, "RSWC_japanese_products")
       empcmd TorontoDB "CREATE REPLICATION REPLICATE
          ${TOKYO_RR_INFO}
          ON ${TORONTOPLIST} WHERE prod_lang = 'japanese';"

    # "------------------- OpG6 ------------------------------------"
    #
    # "${NEWYORKHOST}: OpG6.  Configure Network Server on RRT Side [${NEWYORKPLIST}] "
    # Steps of OpG6 are to be executed if ${NEWYORKHOST} and ${TORONTOHOST} are
    # different. Otherwise, these is no need to create the files once more.
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVER} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpG7 ------------------------------------"
    #
    # "${NEWYORKDB}: OpG7. Create Replicate Table [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    empbatch ${NEWYORKDB} << @
       create and insert into replicate table \
            ${NEWYORKPLIST}  \
            FROM ${TORONTO_RM_INFO};
    @

    # "------------------- OpG8 ------------------------------------"
    #
    # "${TOKYOHOST}: OpG8.  Configure Network Server on RRT Side [${TOKYOPLIST}] "
    # Steps of OpG8 are to be executed if ${TOKYOHOST} and ${TORONTOHOST} are
    # different. Otherwise, these is no need to create the files once more.
    if [ ! -d ${HOME}/.empress ]
    then
       mkdir ${HOME}/.empress
    fi

    cat > ${NETSERVERTOKYO} << @
    MSNETSERVER
        NAME=${TORONTOREPSERVER}
        TYPE=${SERVERTYPE}
        HOST=${TORONTOHOST}
        PORT_ADMIN=12340
        PORT_SERVICE=12345
        ADMINISTRATOR=${USER}
    MSNETSERVEREND
    @

    # "------------------- OpG9 ------------------------------------"
    #
    # "${TOKYODB}: OpG9. Create Replicate Table [{TOKYOPLIST}, ${TORONTOPLIST}] "
    empbatch ${TOKYODB} << @
       create and insert into replicate table \
            ${TOKYOPLIST}  \
            FROM ${TORONTO_RM_INFO};
    @

    # "------------------- OpG10 ------------------------------------"
    #
    # "${NEWYORKHOST}: OpG10. Perform a Synchronization [${NEWYORKPLIST}]"
       emprepsync -v ${NEWYORKDB} ${NEWYORKPLIST}

    # "------------------- OpG11 ------------------------------------"
    #
    # "${TOKYOHOST}: OpG11. Perform a Synchronization [${TOKYOPLIST}]"
       emprepsync -v ${TOKYODB} ${TOKYOPLIST}

    # "------------------- OpG12 ------------------------------------"
    #
    # "NewYorkDB: OpG12. View Replication Table and Synchronization Status [NewYorkPList] "
    empbatch ${NEWYORKDB} << @
       display table ${NEWYORKPLIST}  all;
    @

    # "Check the contents of the Replication Replicate Table NewYorkPList"
       empcmd  ${NEWYORKDB} "select * from ${NEWYORKPLIST};"

    # "------------------- OpG13 ------------------------------------"
    #
    # "TokyoDB: OpG13. View Replication Table and Synchronization Status [TokyoPList] "
    empbatch ${TOKYODB} << @
       display table ${TOKYOPLIST}  all;
    @

    # "Check the contents of the Replication Replicate Table NewYorkPList"
       empcmd  ${TOKYODB} "select * from ${TOKYOPLIST};"

### B.8.2 Other possible operations in scenario G

    # "------------------------------------------------------------"
    # "the rest of the commands undo the effects of Scenario 1"
    # "------------------------------------------------------------"

    # "${NEWYORKDB}: Drop Replicate Table [${NEWYORKPLIST}] "
    #   empcmd ${NEWYORKDB} "DROP TABLE ${NEWYORKPLIST};"

    # "${TOKYODB}: Drop Replicate Table [${TOKYOPLIST}] "
    #   empcmd ${NEWYORKDB} "DROP TABLE ${NEWYORKPLIST};"

    # "${TORONTODB}: Unauthorize Replication Replicate [${NEWYORKPLIST}, ${TORONTOPLIST}] "
    #   empcmd ${TORONTODB} "DROP REPLICATION REPLICATE \
    #         ${NEWYORK_RR_INFO} \
    #          ON ${TORONTOPLIST};"

    # "${TORONTOHOST}: Stop Replication Master Server [${TORONTOREPSERVER}]"
       empsvadm ${TORONTOREPSERVER} stop

    # "${TORONTODB}: Undefine Master Table [${TORONTOPLIST}]"
    #   empcmd ${TORONTODB} "ALTER TABLE ${TORONTOPLIST} CHANGE TABLE TYPE TO NORMAL;"

    #---------------------------------------------------------------
    # "Post Steps to completely clear the effects"

    # "Remove database ${NEWYORKDB}"
    #   emprmdb ${NEWYORKDB}
    # "Remove database ${TORONTODB}"
    #   emprmdb ${TORONTODB}
    # "Remove database ${TOKYODB}"
    #   emprmdb ${TOKYODB}
    # "remove server log file"
    #   rm ${TORONTOREPSERVER}.log