2

I am running into an issue that, when my script is run, the MySql section of it isn't working or is dropping the synonym. Is there something else I need to put into the command to have it log into the MySql server and do everything that is stated?

#! /bin/bash

#Subject: Please stage the following TFL09143 Locator Bulletin to all TF90 staging environments:#



#########################################################################
# This next section is to go to mysql server and make changes.          #
# you can drop and create synonyms                                      #
# truncate a table and insert into a different one.                     #
# you will be able to verify the counts to the different locations      #
#########################################################################

$ mysql -h=app03-bsi -u "" -p ""  "TF90BPS" -bse "drop_view TF90.BTXADDR drop_view TF90.BTXSUPB CREATE_VIEW TF90.BTXADDR FOR TF90BP.TFBPS2.BTXADDR CREATE_VIEW TF90.BTXSUPB FOR TF90BP.TFBPS3.BTXSUPB TRUNCATE TABLE TF90BP.TFBPS3.BTXSUPB SELECT (*) FROM TF90BP.TFBPS2.BTXSUPB; select count (*) from TF90BP.TF90.BTXADDR select count(*) from TF90BPS.TF90.BTXADDR; select count(*) from TF90BP.TF90.BTXSUPB; select count(*) from TF90BPS.TF90.BTXSUPB;"

$ mysql -h=app03-bsi -u "" -p ""  "TF90LMS" -bse "drop_view TF90.BTXADDR drop_view TF90.BTXSUPB CREATE_VIEW TF90.BTXADDR FOR TF90LM.TFBPS2.BTXADDR CREATE_VIEW TF90.BTXSUPB FOR TF90LM.TFBPS3.BTXSUPB; TRUNCATE TABLE TF90LM.TFLMS2.BTXADDR;TRUNCATE TABLE TF90LM.TFLMS3.BTXSUPB;INSERT INTO TF90LM.TFLMS3.BTXSUPB SELECT * FROM TF90LM.TFLMS2.BTXSUPB;Verify select count(*) from TF90LM.TF90.BTXADDR;select count(*) from TF90LMS.TF90.BTXADDR;select count(*) from TF90LM.TF90.BTXSUPB;select count(*) from TF90LMS.TF90.BTXSUPB"

$ mysql -h=app03-bsi -u "" -p ""  "TF90NCS" -bse "drop_view TF90.BTXADDR  drop_view TF90.BTXSUPB CREATE_VIEW TF90.BTXADDR FOR TF90NC.TFBPS2.BTXADDR CREATE_VIEW TF90.BTXSUPB FOR TF90NC.TFBPS3.BTXSUPB; TRUNCATE TABLE TF90NC.TFNCS2.BTXADDR; TRUNCATE TABLE TF90NC.TFNCS3.BTXSUPB; INSERT INTO TF90NC.TFNCS3.BTXSUPB SELECT * FROM TF90NC.TFNCS2.BTXSUPB; Verify select count(*) from TF90NC.TF90.BTXADDR; select count(*) from TF90NCS.TF90.BTXADDR;select count(*) from TF90NC.TF90.BTXSUPB;select count(*) from TF90NCS.TF90.BTXSUPB"

$ mysql -h=app03-bsi -u "" -p ""  "TF90PVS" -bse "drop_view TF90.BTXADDR drop_view TF90.BTXSUPB CREATE_VIEW TF90.BTXADDR FOR TF90PV.TFBPS2.BTXADDR CREATE_VIEW TF90.BTXSUPB FOR TF90PV.TFBPS3.BTXSUPB; TRUNCATE TABLE TF90PV.TFPVS2.BTXADDR;TRUNCATE TABLE TF90PV.TFPVS3.BTXSUPB;INSERT INTO TF90PV.TFPVS3.BTXSUPB SELECT * FROM TF90PV.TFPVS2.BTXSUPB;Verify select count(*) from TF90PV.TF90.BTXADDR;select count(*) from TF90PVS.TF90.BTXADDR;select count(*) from TF90PV.TF90.BTXSUPB;select count(*) from TF90PVS.TF90.BTXSUPB"

#TFL09143 Staging#

cd \\ntsrv\common\To\IT-CERT-TEST\TFL09143 #change to mapped network drive 

cp -p TFL09143.pkg /d:/tf90/code_stg /tf90bp/code_stg /tf90lm/code_stg /tf90pv/code_stg 

InvalidInput="true" 

if [ $# -eq 0 ] ; then
    echo "This script sets up TF90 Staging"
    echo -n "Which production do you want to run? (RB/TaxLocator/Cyclic)"
    read ProductionDistro
else
    ProductionDistro="$1"
fi

while [ "$InvalidInput" = "true" ]
do
    if [ "$ProductionDistro" = "RB" -o "$ProductionDistro" = "TaxLocator" -o "$ProductionDistro" = "Cyclic" ] ; then
                    InvalidInput="false"
        break
    else 
        echo "You have entered an error"
        echo "You must type RB or TaxLocator or Cyclic"
        echo "you typed $ProductionDistro"
        echo "This script sets up TF90 Staging"
        read ProductionDistro
    fi
done

InvalidInput="true"

if [ $# -eq 0 ] ; then
    echo "This script sets up RB TF90 Staging"
    echo -n "Which Element do you want to run? (TF90/TF90BP/TF90LM/TF90PV/ALL)"
    read ElementDistro
else
    ElementDistro="$1"
fi

    while [ "$InvalidInput" = "true" ]
do
    if [ "$ElementDistro" = "TF90" -o "$ElementDistro" = "TF90BP" -o "$ElementDistro" = "TF90LM" -o "$ElementDistro" = "TF90PV" -o "$ElementDistro" = "ALL" ] ; then
        InvalidInput="false"
        break
    else 
        echo "You have entered an error"
        echo "You must type TF90 or TF90BP or TF90LM or TF90PV"
        echo "you typed $ElementDistro"
        echo "This script sets up TF90 Staging"
        read ElementDistro
    fi


done 

if [ "$ElementDistro" = "TF90" ] ; then

    cd /d/tf90/code_stg
    vim TFL09143.pkg
    export var=TF90_CONNECT_STRING=DSN=TF90NCS;export Description=TF90NCS;export Trusted_Connection=Yes;export WSID=APP03-
    BSI;export DATABASE=TF90NCS;
    export DATASET=DEFAULT
    yum install -y ../TFL09143.pkg
fi

if [ "$ElementDistro" = "$TF90BP" ] ; then
    cd /d/tf90bp/code_stg
    vim TFL09143.pkg
    export TF90_CONNECT_STRING=DSN=TF90BPS;export Description=TF90BPS;export Trusted_Connection=Yes;export WSID=APP03-
    BSI;export DATABASE=TF90BPS;
    yum install -y ../TFL09143.pkg
fi

if [ "$ElementDistro" = "$TF90LM" ] ; then
    cd /d/tf90lm/code_stg
    vim TFL09143.pkg 
    export TF90_CONNECT_STRING=DSN=TF90LMS;export Description=TF90LMS;export Trusted_Connection=Yes;export WSID=APP03-
    BSI;export DATABASE=TF90LMS;
    yum install -y ../TFL09143.pkg 
fi

if [ "$ElementDistro" = "TF90PV" ] ; then
    cd /d/tf90pv/code_stg
    vim TFL09143.pkg
    export TF90_CONNECT_STRING=DSN=TF90PVS;Description=TF90PVS;Trusted_Connection=Yes;WSID=APP03-
    BSI;DATABASE=TF90PVS;
    yum install -y ../TFL09143.pkg
fi

exit 0
4
  • 1
    You seem to be mixing long-form and short-form options - I don't think --u or --p are valid, they need to be -u and -p or --user= and --password=. I'm also not sure you can chain mysql DROP and CREATE statements with && in that way. Commented Jun 13, 2014 at 17:23
  • I don't believe this is related to your issue, but your giant block of if...else statements is the perfect use-case for a case statement. May be worth looking into :)
    – HalosGhost
    Commented Jun 13, 2014 at 17:39
  • I will change the --u and --p to the right commands and let you know how it is working after that. Also should I take out thee && and replace it with ; to run multiple instances?
    – bgrif
    Commented Jun 13, 2014 at 17:41
  • I have never actually thought about using a case statement. I will look into it more and see if will help in any way.
    – bgrif
    Commented Jun 13, 2014 at 17:43

1 Answer 1

2

I think the major problem here is that MySQL doesn't support synonyms. That's an Oracle thing.

mysql> CREATE SYNONYM info2 FOR info;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SYNONYM info2 FOR info' at line 1

Here is a good link on how to mimic this behaviour (http://blog.mclaughlinsoftware.com/2013/11/24/mysql-synonym/) It uses the CREATE VIEW syntax from MySQL

5
  • Wow i had no idea that mysql doesnt create synonyms. I am looking at the link you shared and going to try to make changes to read. Also i will find out from my work wether or not they are actually using oracle or mysql for it.
    – bgrif
    Commented Jun 13, 2014 at 17:53
  • I changed CREATE SYNONYM and DROP SYNONYM to CREATE_VIEW and ALTER_VIEW. The changes brought up another screen with different commands in it and saved it to a file called --host=app03-bsi
    – bgrif
    Commented Jun 13, 2014 at 18:22
  • That portion is likely due to the scripting section. As mentioned in previous comments to your first post, the "--u" and "--p" should be changed to "-u" and "-p", respectively. Otherwise you will end up with errors like: 'mysql: ambiguous option '--u' (unbuffered, user)'. I personally would work backwards on this. Make sure you have the MySQL right by calling it on the MySQL command line. Then call with mysql in bash, then add that to your script.
    – Falsenames
    Commented Jun 13, 2014 at 19:30
  • thank you. i will work on it like that so I will have the right information in the final script. If I run into anymore areas taht it gives me errors i will update the script on here and let you know.
    – bgrif
    Commented Jun 13, 2014 at 19:36
  • I made the changes that were suggested and still am getting an error on the location of the mysql server. I also now have to figure out how to run the commands for mysql when you choose the ElementDistro.
    – bgrif
    Commented Jun 16, 2014 at 15:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .