Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Read line of files and call store procedures [Urgent]

$
0
0
Hi,

I wish to write a piece of code to read lines of the flat file and cut each lines of record to a variable, then use this variable to pass as an parameter of a Sybase stored procedures, if there are 5 lines of record from the text file, then this stored procedures will be called 5 times.
But I keep on hit the error:
syntax error at line 56 : `<' unmatched

Here are my code:
#!/bin/ksh
. /production/kltools/profiles/profile.cron
ClientDir=/home/abc/
ClientSrcDir=$ClientDir/test
ClientLogDir=$ClientDir/log
ClientTgtDir=$ClientDir/data
ClientScriptDir=$ClientDir/script
Log=$ClientLogDir/load.log
InFile=$ClientTgtDir/test.txt
Log_Temp=$ClientLogDir/load_data.log
rm -f $Log $OutFile
if [[ -f $Log ]]
then
echo "Error: Could not remove log file $Log"
exit 1
fi

if [[ -f $OutFile ]]
then
echo "Error: Could not remove $OutFile" >> $Log
exit 1
fi

# replace
i=0

for line in $InFile
do
COM_NUM=`cut -c138-140 $line`
PLAN=`cut -c141-142 $line`
EMPID=`cut -c65-73 $line`
AMT1=`cut -c148-157 $line`
AMT2=`cut -c158-162 $line`
Comp_code="ABC"
Server="TEST"
Database="SERVER1"
if [[ -f $Log_Temp ]]
then
echo "Error: Could not remove file $Log_Temp"
exit 1
fi
ksql -S $Server <<-EOF >> $Log_Temp
use $Database
go
exec PROD1 '$COM_NUM', '$PLAN', 'EMPID', $AMT1, $AMT2
go
EOF
ReturnStatus=$?
if [[ $ReturnStatus != "0" ]]
then
echo "Error: ksql failure in inserting." >> $Log
exit 1
fi

done

line 56 should be as following:
ksql -S $Server <<-EOF >> $Log_Temp

but I tried to remove the syntax for..loop, then this error not show, however, I need variable to store data from each line (from the test.txt) and pass to procedures.

Thanks in advance.

Viewing all articles
Browse latest Browse all 13329

Trending Articles