0

I want to write a shell script where I will enter any gcloud side environment and I will have multiple docker images that will be running. I will enter as a bash mode in any container and then run the gcloud connect MySQL command which is nothing but a Rubik. How can I enter these using a shell script? The script I have written is like a plain simple::

#!/bin/bash
echo "Executing cluster"
docker exec -ti cluster-name bash
echo "Starting a connection to gcloud mysql"
gcloud sql connect ql03-ee102-mysql --user=root --quiet.

The command is running till "docker exec -ti cluster-name bash" and entering the bash mode inside Rubik but stops running after that and do not run the next statements. If it does then I can create other DB scripts. How Do I achieve it? I am stuck. Any helo would be highly appreciated.

Abhi
  • 41
  • 2
  • 10
  • Hey @Abhinav, do you receive any error message when you try to run this command like "command not found"? Also, I want to mention few things regarding executing commands in Docker container; your container should be running and also the "gcloud" command that your trying to run should be included in the image. so consider creating an image with all the things that you need in addition to the Cloud SDK. Anyway, I'll be waiting for your reply with the error message. – Methkal Khalawi Nov 21 '19 at 13:47
  • The bash script will block on the `gcloud sql connect ...` command and await this command to complete before the script will proceed. You should be able to (I have not tried this) pipe the SQL commands that you wish into it, e.g. `echo "show databases;" | gcloud sql connect ...` *but* you may have challenges capturing its output. – DazWilkin Nov 21 '19 at 19:59

0 Answers0