1

Is there a way to run a shell script that when it updates one sqlplus instance it will update a second?

Code:

echo "Please enter last name: 'input;"
    read input
    Statement2="INSERT INTO users VALUES ('"$input"');"
    output1=$($sqlplus -s User/Pass@connection <<EOF
    set head off
    select count (*) from users
    where fname = '$input';
    EXIT;
    EOF
    )

    read -p "User $input appears $output1 times. Create user? [Y/n]" answer
    if [ -z "$answer" -o "$answer" == "y" -o "$answer" == "Y" ]
    then

    $sqlplus -s User/Pass@connection << Eossql
    set autocommit on
    set head off
    $Statement2
        quit;
    Eossql

    else
        echo "Not creating user"
    fi

How can I update a second sqlpus instance with a separate userid and password if the end user selects (y)

Thanks!

2
  • I think this question is unclear. Perhaps rewrite the question Commented Jul 22, 2017 at 4:52
  • @EdHeal If the user selects "y" in the above code it will run "statement2" which is an insert into the table in instance 1. I was asking if the user selects "y" it will run "statement 2" it two separate instances with separate user ID's and Passwords. Commented Jul 22, 2017 at 5:27

1 Answer 1

1

You can save the SQL code to run on two instances in a variable, and then reuse it:

sql=$(cat << EOF
set autocommit on
set head off
$Statement2
    quit;
EOF
)
$sqlplus -s User/Pass@connection <<< "$sql"
$sqlplus -s User2/Pass2@connection2 <<< "$sql"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.