Skip to main content
Question

Need help on vsql connection in shell script.

  • November 2, 2020
  • 4 replies
  • 7 views

Sankarmn
Forum|alt.badge.img+1

I am using the variables inside shell script. Not a scripting guy, trying to make things work.
My command:

Connection variables

VSQLPATH=/opt/vertica/bin/vsql
TECHNOLOGY=vertica
HOST=xxxxxx.com
PORT=5433
DB_NAME=glider
USERNAME=cuser
if [ "${TECHNOLOGY}" = "vertica" ]
then
export PASSWORD="${PWD}"
${VSQLPATH} --host="${HOST}" --port="${PORT}" --username="${USERNAME}" --dbname="${DB_NAME}" -w "${PWD}" |tee -a ${log_file}
fi

I should get connected output in log file and it has to disconnect to complete the script. Right now its showing "connecting to the database" and hangs in there forever. Need help.

4 replies

Jim_Knicely
Forum|alt.badge.img+2
  • Participating Frequently
  • November 2, 2020

Not exactly sure what you are trying to do, but you could just use the -c option to pass in a simple command to run, then vsql will exit.

I am also using the -o option to output to a file (i.e. a log file).

[dbadmin@localhost ~]$ cat l.sh
VSQLPATH=/opt/vertica/bin/vsql
TECHNOLOGY=vertica
HOST=*******
PORT=5433
DB_NAME=verticademos
USERNAME=dbadmin
PWD=*****
log_file=/home/dbadmin/log.txt
if [ "${TECHNOLOGY}" = "vertica" ]
then
export PASSWORD="${PWD}"
${VSQLPATH} --host="${HOST}" --port="${PORT}" --username="${USERNAME}" --dbname="${DB_NAME}" -w "${PWD}" -c "SELECT version();" -o ${log_file}
fi

[dbadmin@localhost ~]$ ./l.sh

[dbadmin@localhost ~]$ cat log.txt
               version
-------------------------------------
 Vertica Analytic Database v10.0.1-2
(1 row)

Sankarmn
Forum|alt.badge.img+1
  • Author
  • Participating Frequently
  • November 2, 2020

Appreciated Jim.

I was thinking in line to use option -c, but I don't need any VSQL output so I omitted.
When you manually connect to VSQL from command line it connects and you get the "welcome to vsql" screen and do '\q' to exit.
How do we do this? or just simply 'connected' and 'exit' outputs in log file to confirm a connection was made successfully with the supplied credentials.
TIA


Jim_Knicely
Forum|alt.badge.img+2
  • Participating Frequently
  • November 2, 2020

This works:

[dbadmin@localhost ~]$ vsql -q -c "\q"


Sankarmn
Forum|alt.badge.img+1
  • Author
  • Participating Frequently
  • November 2, 2020

Appreciated Jim