1

I'm having difficulties passing a env var (declared in my .bash_profile) to a batch file script which executes a BTEQ operation (in Teradata).

.bash_profile contains:

export DBPASSWORD='password'

BATCH file contains:

bteq < bteq_execution_test.sql > bteq_execution_test.log 2>&1 ${DBPASSWORD}

I checked that ${DBPASSWORD} was, in fact, getting passed into the file - but it is NOT being properly accepted as the password in the BTEQ script which looks something like this (the log on portion is where there is an error):

.logon mydb/username,$4;

Note: I'm referencing the ${DBPASSWORD} env var set password by position. Please let me know if anyone could lend a hand. Thank you in advance!

  • @ClassStacker: The order is not important in most shells – < input cmd > output arg1 arg2 works just as well as cmd arg1 arg2 < input > output. – user1686 Dec 18 '15 at 7:27
  • On second look. There's no $4 here. bash treats redirections by itself, they will not be visible to a script. If bteq is a script then it will see the DBPASSWORD parameter as $1 regardless of whether it is placed before or after the redirections. – Run CMD Dec 18 '15 at 8:20
0

So I figured it out and it's a solution that will work generally regardless of the actual command to be run in the terminal. The way I did this was to create a "setup" batch file which runs a bunch of "echo" commands and writes them out to a second file to be executed by BTEQ (in my example). Here's how I solved it (please refer to the context in my original post):

bteq_execution_test_setup.bat:

rm bteq_execution_test_setup1.bat
echo '.LOGON mydb/username,' ${DBPASSWORD} ';' > bteq_execution_test_setup1.bat
echo 'insert into mydb.mytable select top 10 feature1, feature2 from mydb.another_table;' >> bteq_execution_test_setup1.bat
echo '.LOGOFF;' >> bteq_execution_test_setup1.bat
echo '.EXIT;' >> bteq_execution_test_setup1.bat
bteq < bteq_execution_test_setup1.bat > bteq_execution_test_setup1.log 2>&1 

Then simply executing the command:

./bteq_execution_test_setup.bat

will execute the command (BTEQ in this case) WITH the desired env var declared in your .bash_profile (or .bashrc, .profile, etc). Hope this helps someone, I saw a LOT of people asking about this on the Teradata forums!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.