Need help on vsql connection in shell script.
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.
Best Answer
-
Jim_Knicely - Select Field - Administrator
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)
-1
Answers
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
This works:
[dbadmin@localhost ~]$ vsql -q -c "\q"
Appreciated Jim