Please take this survey to help us learn more about how you use third party tools. Your input is greatly appreciated!

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_KnicelyJim_Knicely Administrator
    Accepted Answer

    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).

    [[email protected] ~]$ 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
    
    [[email protected] ~]$ ./l.sh
    
    [[email protected] ~]$ cat log.txt
                   version
    -------------------------------------
     Vertica Analytic Database v10.0.1-2
    (1 row)
    

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

  • Jim_KnicelyJim_Knicely Administrator
    edited November 2

    This works:

    [[email protected] ~]$ vsql -q -c "\q"

  • Appreciated Jim

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file

Can't find what you're looking for? Search the Vertica Documentation, Knowledge Base, or Blog for more information.