Options

Need help on vsql connection in shell script.

SankarmnSankarmn Community Edition User ✭✭

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

  • Options
    Jim_KnicelyJim_Knicely - Select Field - Administrator
    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).

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

Answers

  • Options
    SankarmnSankarmn Community Edition User ✭✭

    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

  • Options
    Jim_KnicelyJim_Knicely - Select Field - Administrator
    edited November 2020

    This works:

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

  • Options
    SankarmnSankarmn Community Edition User ✭✭

    Appreciated Jim

Leave a Comment

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