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. Here are my code:
InFile=test.txt
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
However, I keep on hit the error as below:
syntax error at line 56 : `<' unmatched
I cannot have the procedures call within the for loop?
Showing us that you have a syntax error on line 56 of a 30 line shell script tells us that you are not showing us the script that generated the diagnostic message you reported. Could this diagnostic be coming from PROD1 ?
You use $Log and $Log_Temp , but neither of these variables are set in this script.
#!/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