1

by expect script we create the database hive and some other commands

in case we run the expect script again on the machine that hive already created

then we get - ERROR hive already exists

so how to verify database hive already created ?

And by this verification we can escape the expect script

# su - postgres
 Last login: Sun Aug 13 11:12:03 UTC 2017 on pts/0
 -bash-4.2$ psql
 psql (9.2.13)
 Type "help" for help.

postgres=# CREATE DATABASE hive;
ERROR:  database "hive" already exists

my expect script: ( from my bash script )

set timeout -1

#exec the scripts

spawn timeout 60 ssh root@IP
expect "#"
spawn su - postgres
expect "$"
send "psql\n"
expect "=#"
send "CREATE DATABASE hive;\n"
.
.
.
.
-3

you can use IF EXISTS clause:

create database if exists hive;
  • 1
    Welcome to DBA.SE. We appreciate your contribution/participation. However, the community does expect a certain quality in the questions and answers posted. Please consider reading the following article: How do I write a good answer? (Help Centre) In the section Answer the question there is a short sentence which reads: Brevity is acceptable, but fuller explanations are better. Please edit your answer and add some details. Thank you. – John K. N. Aug 14 '18 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.