Question

I have the client/TTU installed on Unix box for Teradata.

If I do the following, it works. Where "..." is Teradata BTEQ normal output and once the following is done, I'm back at the prompt.

$ bteq
...
....

. logon dbname/dbuser,dbpassword
SELECT DATE, TIME;
.LOGOFF;
.QUIT;

..
...
$

Now, lets say I put the following lines in a file called "testtd.bteq"

. logon dbname/dbuser,$dbpassword
SELECT DATE, TIME;
.LOGOFF;
.QUIT;

What I want now is ... how can I run this script (.bteq) at Unix $ prompt ???

I tried the following methods so far, but they didn't work, may be Im missing anything:
1. bteq < /path/to/testtd.bteq > testtd.log

2. bteq < .run /path/to/testtd.bteq
HereDocEndsHere

Any ideas? DO I HAVE to provide ". logon dbname/dbuser,dbpassword" FIRST, if I'm using the HereDocument way?

Running bteq command on $ prompt doesn't even give me any HELP/options that I can use, like other commands.

i.e. cmd -u user -p password -f file etc...

Was it helpful?

Solution 2

PS - It works via method 1 -- when I hard code the password in the script file for LOGON command.

I wanted to do the same via exporting a variable called "dbpassword"

i.e.

$ export dbpassword=xyxyxyxyx

and

then, inside the script file, i can use "$dbpassword" ... in the LOGON command.. somehow export is not exporting the var within .bteq logon command.

OTHER TIPS

The best practice I'm aware of is

  1. store your teradata credentials in a ~/.tdlogon file
  2. create a script that contains your bteq call with all the stuff it needs.

E.g., create a file bteqScript.sh with

/* define helper variables, e.g.... */
export ARCHIVEDIR=~/data
export DATAFILE=dataOutput1.txt
bteq <<EOF
.run file=$HOME/.tdlogon
.export data file=${ARCHIVEDIR}|${DATAFILE} 
/* sql code on next line(s) */
select 
    'foo' as "bar"
; 
.export reset
EOF

Note that .run file=... executes the .logon command with your credentials, stored elsewhere.

Kudos to Alex Hasha for the bteq script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top