How to write BTEQ batch scripts in UNIX?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to write BTEQ batch scripts in UNIX?
# 1  
Old 07-08-2015
How to write BTEQ batch scripts in UNIX?

Hi All,

I need to write Unix shell script. To star with : I need to do some file checking on unix file system, then based on file existance, I need to run diff SQL in Teradata Bteq. After that, depending on Results of SQL, I need to code other shell scripting like moving file, within same script.
My script look like:

step1 :- Unix commands...
step2 :- Unix commands...
step3 :- Unix commands...
step4 :- BTeq Login
step5 :- Teradata SQL..
step6 :- BTEQ Logoff
step7 :- Unix Commands..
step8 :- Unix COmmands..

For this I m using code like :

Code:
  
 echo 'unix command'
echo 'unix command'
bteq << EOF
.logon <systemid>/<userid>,<password>;
select current_timestamp;
.logoff;
.quit;
EOF
echo 'unix command 3'
echo 'unix command 4'
echo 'unix command 5'

But getting error like:
syntax error: unexpected end of file

But I executed separately shell script and Bteq batch , it is working fine to me.

Please let me Know how to invoke bteq batch in shell script.

Thanks,
Shilpi Gupta
# 2  
Old 07-08-2015
<< EOF tells it to wait for a line that is exactly "space" "EOF".

Try <<EOF
# 3  
Old 07-08-2015
You'll also get unexpected end of file if you've an if without fi or while without done, etc... as well as missing quotes. The latter usually prints two errors though in bash:

Code:
./script: line 4: unexpected EOF while looking for matching `"'
./script: line 7: syntax error: unexpected end of file

We'll need actual code and actual output to assist further.
# 4  
Old 07-09-2015
Hi Neutronscott,

Please find below code:

Code:
  
 clear
 DB_FIND()
 {
  IFS=$'\n'
  set -f
  echo "=================$BTEQ_NAME=================="
  while read i; do
  DB_Name=$i
  /usr/xpg4/bin/awk -v target=$DB_Name '{for(i=1;i<=NF;i++)if($i ~ target) print $(i)}' $BTEQ_NAME  > ${DB_Name}_TableList.txt
  sed '/FOLDR/d' ${DB_Name}_TableList.txt > ${DB_Name}_IFile.txt
  /usr/xpg4/bin/awk '!x[$0]++' ${DB_Name}_IFile.txt > ${DB_Name}_File.txt
  rm ${DB_Name}_IFile.txt
  rm ${DB_Name}_TableList.txt
  if [ -s ${DB_Name}_File.txt ] ; then
     echo ${DB_Name}_File.txt
      conn_string=`ksh /apps/cronacle/tools/teradata/.otherdetails/.Info_4ETL.sh UID_ODS_CLP_DRG`
     export conn_string;
     bteq <<EOF
     .logon ${conn_string};
     .export report FILE = /ftp/SrcFiles/src/SSSS/sample.txt;
     .SET SEPARATOR '|'
     SELECT * FROM dbc.tables where tablename='AP_INVC_F_V';
     .logoff
     .quit;
     EOF
 
  fi;
   done <Param.txt
 
}
  
 # Main Body of this Script
BTEQ_NAME_LIST=$1
 
for i in `cat ${BTEQ_NAME_LIST}` ; do
BTEQ_NAME=`echo "${i}" | awk -F"|" '{ print $1 }'`;
export BTEQ_NAME;
 BTEQ_PARAM_FILE=`awk '{for(i=1;i<=NF;i++)if($i~/\/bin/)print $(i)}' $BTEQ_NAME|cut -d"/" -f8|cut -d";" -f1`
 awk '{for(i=1;i<=NF;i++)if($i~/\=/)print $(i)}' $BTEQ_PARAM_FILE|cut -d"=" -f1 > ParamP1.txt
 awk '{for(i=1;i<=NF;i++)if($i~/_/)print $(i)}' ParamP1.txt > Param.txt
 #rm ParamP1.txt
 DB_FIND
 #rm Param.txt
 done


Getting Output as:

./DB_Validation_1.sh: line 66: syntax error: unexpected end of file

This script was working fine, when I m not inserting any Bteq batch inside it..

Please help me to find root cause behind this..
# 5  
Old 07-09-2015
EOF must not have any whitespace before it. There's an exception in bash if you use <<-EOF.

From Bash Reference Manual: Here Documents:

Quote:
This type of redirection instructs the shell to read input from the current source until a line containing only word (with no trailing blanks) is seen. All of the lines read up to that point are then used as the standard input for a command.

...

If the redirection operator is ‘<<-’, then all leading tab characters are stripped from input lines and the line containing delimiter. This allows here-documents within shell scripts to be indented in a natural fashion.
edit: i see you're calling ksh. <<- applies to ksh88/93 as well if you decide to indent with tabs.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

How to write a script to run without password on a batch of servers?

I need run a command such as ps -ef |grep xxx on a batch of servers, how to write a script to run it without password? don't need go in each server to check? Thanks (7 Replies)
Discussion started by: rainbow_bean
7 Replies

2. UNIX for Dummies Questions & Answers

Need equialent command for batch scripts

Hi Friend, what is the equivalent command for batch scripting of tail -1. for example : i have a.txt file with below the contents. i need to print last line --------------------------------- Use descriptive thread titles when posting. For example, do not post questions with subjects like... (3 Replies)
Discussion started by: Jewel
3 Replies

3. Shell Programming and Scripting

Teradata connectivity through UNIX by use bteq

Hi, I want a script for connecting teradata to load the file to teradata table. Can you please help me out. Thanks in advance. (1 Reply)
Discussion started by: victory
1 Replies

4. Shell Programming and Scripting

Batch write multiple usb in same time

Hi there, I would write a bash script to format then create a range of folder (folder name is number) to a usb stick. for numbers in $(seq -w 001 999) do pause "Press any key to start" mkfs.vfat -F32 /dev/sdc1 mount /dev/sdc1 /media/usb mkdir /media/$numbers umount /dev/sdc1... (8 Replies)
Discussion started by: wayneliao38
8 Replies

5. Shell Programming and Scripting

How to batch-processing numerous shell scripts?

How to batch-processing numerous shell scripts? how to record the result of all the scripts as a report? then, I can analysis the process result. I want to process numerous shell scripts in my working directory: the directory name is consistent with shell scripts name, that is to say,... (2 Replies)
Discussion started by: qcmao
2 Replies

6. Shell Programming and Scripting

HowTo translate KSH Scripts to DOS Batch Files ?

Hi there, in near future I have to change my work surrounding from HP UNIX to Windows Vista (great to get rid of old hardware :), but bad to loose UNIX :( ). As I heavily use KSH scripts to do my job, I was wondering, if there is any HowTo available, supporting me in re-writing the scripts to... (4 Replies)
Discussion started by: Joe-K7
4 Replies

7. Shell Programming and Scripting

Running shell scripts automatically without using Batch or at commands

I have been trying to run a unix script which contains many sql statements.I need to run this script every monday morning. I tried to run on command prompt, it works fine. But while I run it via batch or at command., it returns with library module could not be loaded (libcompat.1.o could not be... (3 Replies)
Discussion started by: ritzwan0
3 Replies

8. Shell Programming and Scripting

How to write a Script to run series of batch jobs on unix platform

Im new to unix shell scripting, I have to run batch jobs on unix. for example i have 5 jobs. first 2 can kickoff parallely. after completely finishing the 2 previous jobs the 3 job should kick off..once 3rd is over 4 th and 5th can kick off parallely. Each jobs run for 1 or 2 hours each. How to... (2 Replies)
Discussion started by: venki311
2 Replies

9. UNIX for Dummies Questions & Answers

How can I run scripts in my unix account from batch file in Windows?

Hi all, I'm working on Windows, connecting to my Unix account by different ways: by FTP opening files in UltraEdit32, by mapping drive to browse, by Exceed or Telnet to compile at Unix account. Actually, that is what I would like to change: I'd like to make a batch file which would connect to... (7 Replies)
Discussion started by: olgafb
7 Replies

10. UNIX for Dummies Questions & Answers

Learning to write UNIX Shell Scripts

Hi All, I am relatively new to UNIX. I know some basic commands. I am learning to write shell scripts. My first aim is to connect to a Data Base via shell script. Any ideas on this? Any links, docs which will tell me about scripting?? Thanks VEN (1 Reply)
Discussion started by: VENC22
1 Replies
Login or Register to Ask a Question