Error with nested if within an sqlplus task inside


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error with nested if within an sqlplus task inside
# 1  
Old 10-07-2013
Error with nested if within an sqlplus task inside

Hi ALL,

I am receving a "strange" error using a nested if within an sql operation inside:
./dom.ksh[71]: syntax error at line 80 : `then' unmatched

This is all my script code: in bold the step receiving the error.

Any help would really aprrecieted ......!

**** I have tried all the possible syntax also consulting other forum discussions about shells script but unfortunately without success ........
if [[ $SKIP_ARBOR = skipArbor ]]
if [ $SKIP_ARBOR = skipArbor ]
if [[ "$SKIP_ARBOR" = "skipArbor" ]]
if [ ${SKIP_ARBOR} = skipArbor ]
if [ "${SKIP_ARBOR}" = "skipArbor" ]
if [ "${SKIP_ARBOR}" = skipArbor ]

etc .......

Operating System: HP-UX B.11.31 U 64 bit ia64
Tks in advance.

Ciao
Andrea


BFCMCA01 arbfclmg@fxclbs02:/servizio_collmigrf/MIGRAZIONE/QQL/shell/arbor> cat dom.ksh
Code:
 
#!/usr/bin/ksh
#****************************************************************
# Descrizione : Estrae tutti i dati dalla entitą C09_Hash 
# 
# Nome Script : Estrai_A91_C09_Hash.ksh
#
#****************************************************************
# History
#****************************************************************
# Ver. | Data | Note 
#****************************************************************
# 1.0 | 16/08/13 | Prima versione
# 1.1 | 16/09/13 | Seconda Versione:
# Aggiunta gestione del codice d'uscita
# 0 -> OK 1 -> NOK
# Modificato path QQL_CFG e INIT_ARBOR e
# INIT_KENAN per Gestione Automatica
# | | 
#----------------------------------------------------------------
# | | 
#----------------------------------------------------------------
# | |
#****************************************************************
clear
 
#Acquisisco parametri
DB_INPUT=$1
DB_INPUT_KFX=$2
TABLE_SPACE_INPUT=$3
 
#Controllo che siano stati passati i tre parametri obbligatori richiesti
# #1 Istanza DBArbor DBKenan TBSKenan
 
if [ $# -lt 3 ]
then
echo "Parametri di Input non corretti (databaseArbor databaseKenan tablespaceKenan)"
echo "Usage : $0 DBARBOR DBKENAN USERS"
echo "Example : $0 DBARBOR DBKENAN USERS"
echo "Script non eseguito per parametri input errati (databaseArbor databaseKenan tablespaceKenan)"
exit 1
fi
 
#Verifica se quarto argomento passato
if [ $# -eq 4 ]
then
SKIP_ARBOR=$4
else
SKIP_ARBOR="noSkipArbor"
fi
 
echo $SKIP_ARBOR
sleep 1
 
QQ_CFG="$QQL_HOME/cfg/$DB_INPUT/qql.cfg"
if [ ! -r $QQ_CFG ]
then
DATE=$(date "+%D %H:%M:%S")
echo "$DATE MSGERR: ATTENZIONE...."
echo "$DATE MSGERR: Il file ${QQ_CFG} non esiste o non ha i permessi di lettura"
exit 1
fi
. $QQ_CFG
 
PRG_NAME=`basename $0`
PRG_NAME=`echo $PRG_NAME | awk '{print substr($1, 1, length($1) - 4)}'`
data=`date '+%Y%m%d_%H%M%S'`
DB_INPUT=$1
 
#Inizio Script
echo "Inizio script: [$PRG_NAME]"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Inizio script: [$PRG_NAME]"
 
########################################################################
# 1 STEP
########################################################################
#se come quarto argomento di input allo script viene passato "skipArbor"
#la fase di estrazione da Arbor non viene eseguita
 
if [[ $SKIP_ARBOR = skipArbor ]]
then
#Definisco seconda query da lanciare su Arbor
S_CREA_A91_C09_I_APPO="CreateTable_A91_C09_Appo.sql"
 
#creo tabella temporanea su Arbor prima di lanciare caricamento dati estratto da Kenan
echo "Creo tabella temporanea su Arbor - DB CUSTOMER: $S_CREA_A91_C09_I_APPO"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Creo tabella temporanea su Kenan - DB CUSTOMER: $S_CREA_A91_C09_I_APPO"
 
LOGSQL=${PATH_LOG}"/$S_CREA_A91_C09_I_APPO"_"${DB_INPUT}_"`hostname`"_"`date '+%Y%m%d_%H:%M:%S'`".log"
echo "Eseguo $S_CREA_A91_C09_I_APPO sul DB $DB_INPUT. Per l'esito controllare l'apposito file di log: $LOGSQL"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Eseguo $S_CREA_A91_C09_I_APPO sul DB $DB_INPUT. Per l'esito controllare l'apposito file di log: $LOGSQL"
# 2 parametri input: tablespace + nome database
nohup sqlplus -s /nolog << EOF >> ${LOGSQL}
connect $USR_DB_OPER/$PWD_DB_OPER@$DB_INPUT
@$PATH_SQL_ARBOR/$S_CREA_A91_C09_I_APPO ${TABLE_SPACE_INPUT} ${DB_INPUT} ${PATH_LOG}
quit;
EOF
else
echo "Estrazione da Arbor non eseguita come richiesto da argomento passato: $4"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Estrazione da Arbor non eseguita come richiesto da argomento passato: $4"
fi
 
# IF CASE per Gestione Codice Uscita Script Creazione Tabella Arbor 0-> OK 1-> NOK
 
if [ $? -ne 0 ];
then
echo "ERRORE in Procedura SQL: $S_CREA_A91_C09_I_APPO NOK"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "ERRORE in Procedura SQL:$S_CREA_A91_C09_I_APPO NOK"
echo ""
exit 1
else
echo "Completata creazione tabella temporanea Arbor"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Completata creazione tabella temporanea Arbor"
fi
 
########################################################################
 
 
########################################################################
# 2 STEP
########################################################################
#Definisco prima query da lanciare su Arbor
S_ESTRAI_A91_C09_QUERY_I="A91_C09_I.sql"
echo "Eseguo query DB CUSTOMER: $S_ESTRAI_A91_C09_QUERY_I"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Eseguo query DB CUSTOMER: $S_ESTRAI_A91_C09_QUERY_I"
 
#file che verrą creato
FILE_DAT_OUTPUT="A91_C09_I_$DB_INPUT.dat"
 
LOGSQL=${PATH_LOG}"/$S_ESTRAI_A91_C09_QUERY_I"_"${DB_INPUT}_"`hostname`"_"`date '+%Y%m%d_%H:%M:%S'`".log"
echo "Eseguo $S_ESTRAI_A91_C09_QUERY_I sul DB $DB_INPUT. Per l'esito controllare l'apposito file di log: $LOGSQL"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Eseguo $S_ESTRAI_A91_C09_QUERY_I sul DB $DB_INPUT. Per l'esito controllare l'apposito file di log: $LOGSQL"
# 2 parametri input: tablespace + nome database
nohup sqlplus -s /nolog << EOF >> ${LOGSQL}
connect $USR_DB_OPER/$PWD_DB_OPER@$DB_INPUT
@$PATH_SQL_ARBOR/$S_ESTRAI_A91_C09_QUERY_I $PATH_DAT_ARBOR/${FILE_DAT_OUTPUT} "'${DB_INPUT}'"
quit;
EOF
 
# IF CASE per Gestione Codice Uscita script 0-> OK 1-> NOK
 
if [ $? -ne 0 ];
then
echo "ERRORE in Procedura SQL:$S_ESTRAI_A91_C09_QUERY NOK"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "ERRORE in Procedura SQL:$S_ESTRAI_A91_C09_QUERY NOK"
echo ""
exit 1
fi
 
checkSqlError $LOGSQL
 
if (( $? > 0 ))
then
echo "ERRORE in Procedura SQL:$S_ESTRAI_A91_C09_QUERY NOK"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "ERRORE in Procedura SQL:$S_ESTRAI_A91_C09_QUERY NOK"
exit 1
else
echo "Procedura SQL: $S_ESTRAI_A91_C09_QUERY Terminata Correttamente OK"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Procedura SQL: $S_ESTRAI_A91_C09_QUERY Terminata Correttamente OK"
echo ""
echo "Completata estrazione dati da Arbor"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Completata estrazione dati da Arbor"
fi
 
########################################################################
 
 
########################################################################
# 3 STEP
########################################################################
# imposto ambiente KENAN
#per andare su kenan si utilizza il file di configurazione specifico
INIT_KENAN="$PATH_CFG/init_kenan.ksh"
if [ ! -r $INIT_KENAN ]
then
DATE=$(date "+%D %H:%M:%S")
echo "$DATE MSGERR: ATTENZIONE...."
echo "$DATE MSGERR: Il file ${INIT_KENAN} non esiste o non ha i permessi di lettura"
exit 1
fi
. $INIT_KENAN
 
echo "Impostato Ambiente Kenan"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Impostato Ambiente Kenan"
 
#Definisco seconda query da lanciare su Kenan
S_CREA_KFX_C09_I_APPO="CreateTable_KFX_C09_Appo.sql"
 
#creo tabella temporanea su kenan prima di lanciare caricamento dati estratto da Abor
echo "Creo tabella temporanea su Kenan - DB CUSTOMER: $S_CREA_KFX_C09_I_APPO"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Creo tabella temporanea su Kenan - DB CUSTOMER: $S_CREA_KFX_C09_I_APPO"
 
LOGSQL=${PATH_LOG}"/$S_CREA_KFX_C09_I_APPO"_"${DB_INPUT}_"`hostname`"_"`date '+%Y%m%d_%H:%M:%S'`".log"
echo "Eseguo $S_CREA_KFX_C09_I_APPO sul DB $DB_INPUT. Per l'esito controllare l'apposito file di log: $LOGSQL"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Eseguo $S_CREA_KFX_C09_I_APPO sul DB $DB_INPUT. Per l'esito controllare l'apposito file di log: $LOGSQL"
# 2 parametri input: tablespace + nome database
nohup sqlplus -s /nolog << EOF >> ${LOGSQL}
connect $USR_DB_XBSDBO/$PWD_DB_XBSDBO@$DB_INPUT_KFX
@$PATH_SQL_KFX/$S_CREA_KFX_C09_I_APPO ${TABLE_SPACE_INPUT} ${DB_INPUT_KFX} ${PATH_LOG}
quit;
EOF
 
# IF CASE per Gestione Codice Uscita Script Creazione Tabella Kenan 0-> OK 1-> NOK
 
if [ $? -ne 0 ];
then
echo "ERRORE in Procedura SQL: $S_CREA_KFX_C09_I_APPO NOK"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "ERRORE in Procedura SQL:$S_CREA_KFX_C09_I_APPO NOK"
echo ""
exit 1
else
echo "Completata creazione tabella temporanea Kenan"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Completata creazione tabella temporanea Kenan"
fi
 
#Fine creazione tabella temporanea Kenan
 
########################################################################
 
########################################################################
# 4 STEP
########################################################################
echo "Preparo caricamento dati su Kenan"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Preparo caricamento dati su Kenan"
 
#Definisco seconda query da lanciare su Kenan
S_IMPORT_KFX_C09_I="Carica_A91_C09.ctl"
S_IMPORT_KFX_C09_I_CTL=$PATH_SQL_CTL/"Carica_A91_C09.ctl"
 
LOGSQL=${PATH_LOG}"/$S_IMPORT_KFX_C09_I_CTL"_"${DB_INPUT}_"`hostname`"_"`date '+%Y%m%d_%H:%M:%S'`".log"
LOGCTL=${PATH_LOG}"/$S_IMPORT_KFX_C09_I"_"${DB_INPUT}_"`hostname`"_"`date '+%Y%m%d_%H:%M:%S'`".log"
FILE_BAD=$PATH_DAT_KENAN/"A91_C09_"$DB_INPUT_I".bad"
FILE_DISCARD=$PATH_DAT_KENAN/"A91_C09_"$DB_INPUT_I".dis"
 
sqlldr "userid="$USR_DB_XBSDBO"/"$PWD_DB_XBSDBO"@"$DB_INPUT_KFX "CONTROL="$S_IMPORT_KFX_C09_I_CTL "LOG="$LOGCTL "BAD="$FILE_BAD "DATA="$PATH_DAT_ARBOR/$FILE_DAT_OUTPUT "DISCARD="$FILE_DISCARD SILENT=HEADER SILENT=FEEDBACK
 
# IF CASE per Gestione Codice Uscita script 0-> OK 1-> NOK
 
if [ $? -ne 0 ];
then
echo "ERRORE Caricamento dati su Kenan: NOK"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "ERRORE Caricamento dati su Kenan: NOK"
echo ""
exit 1
else
echo "Caricamento dati completato su Kenan"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Caricamento dati completato su Kenan"
fi
 
########################################################################
# 5 STEP
########################################################################
#Eseguo estrazione per ARBOR ma da KENAN
S_ESTRAI_A91_C09_QUERY="A91_C09_H.sql"
FILE_DAT="A91_C09_$DB_INPUT.dat"
 
echo "Eseguo estrazione finale per Arbor da Kenan"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Eseguo estrazione finale per Arbor da Kenan"
 
echo "Eseguo query DB CUSTOMER: $S_ESTRAI_A91_C09_QUERY"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Eseguo query DB CUSTOMER: $S_ESTRAI_A91_C09_QUERY"
 
LOGSQL=${PATH_LOG}"/$S_ESTRAI_A91_C09_QUERY"_"${DB_INPUT}_"`hostname`"_"`date '+%Y%m%d_%H:%M:%S'`".log"
echo "Eseguo $S_ESTRAI_A91_C09_QUERY sul DB $DB_INPUT. Per l'esito controllare l'apposito file di log: $LOGSQL"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Eseguo $S_ESTRAI_A91_C09_QUERY sul DB $DB_INPUT. Per l'esito controllare l'apposito file di log: $LOGSQL"
 
nohup sqlplus -s /nolog << EOF >> ${LOGSQL}
connect $USR_DB_XBSDBO/$PWD_DB_XBSDBO@$DB_INPUT_KFX
#@$PATH_SQL_ARBOR/$S_ESTRAI_A91_C09_QUERY $PATH_DAT_ARBOR/${FILE_DAT} ${DB_INPUT_CATALOG}
@$PATH_SQL_ARBOR/$S_ESTRAI_A91_C09_QUERY $PATH_DAT_ARBOR/${FILE_DAT} "'${DB_INPUT}'"
quit;
EOF
 
# IF CASE per Gestione Codice Uscita script 0-> OK 1-> NOK
 
if [ $? -ne 0 ];
then
echo "ERRORE in Procedura SQL:$S_ESTRAI_A91_C09_QUERY NOK"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "ERRORE in Procedura SQL:$S_ESTRAI_A91_C09_QUERY NOK"
echo ""
exit 1
fi
 
checkSqlError $LOGSQL
 
if (( $? > 0 ))
then
echo "ERRORE in Procedura SQL:$S_ESTRAI_A91_C09_QUERY NOK"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "ERRORE in Procedura SQL:$S_ESTRAI_A91_C09_QUERY NOK"
exit 1
else
echo "Procedura SQL: $S_ESTRAI_A91_C09_QUERY Terminata Correttamente OK"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Procedura SQL: $S_ESTRAI_A91_C09_QUERY Terminata Correttamente OK"
echo ""
echo "Estrazione finale per Arbor completata"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Estrazione finale per Arbor completata"
echo ""
sleep 1
echo "Eseguo cancellazione file DAT temporaneo: $PATH_DAT_ARBOR/${FILE_DAT_OUTPUT}"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Eseguo cancellazione file DAT temporaneo: $PATH_DAT_ARBOR/${FILE_DAT_OUTPUT}"
#rm $PATH_DAT_ARBOR/$FILE_DAT_OUTPUT
echo "Fine script: [$PRG_NAME]"
logInfo $PRG_NAME $DB_INPUT $DB_INPUT_KFX "Fine script: [$PRG_NAME]"
exit 0
fi
 
###################################################################


Last edited by AndreaCecco; 10-07-2013 at 08:02 AM..
# 2  
Old 10-07-2013
Please use code tag

it's working....

Code:
$ ksh test.sh
Parametri di Input non corretti (databaseArbor databaseKenan tablespaceKenan)
Usage : t.sh DBARBOR DBKENAN USERS
Example : t.sh DBARBOR DBKENAN USERS
Script non eseguito per parametri input errati (databaseArbor databaseKenan tablespaceKenan)


Last edited by Akshay Hegde; 10-07-2013 at 07:59 AM..
# 3  
Old 10-10-2013
NO if you pass all the parameters it did not work ......... Now I have seen that I have no to indent the sqlplus ....... in this way it works!
But reallyI do not know the reason why ....... Smilie

Any possible explanation will be apprecieted.

CIAO.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sqlplus error - sqlplus -s <login/password@dbname> : No such file or directory

i am using bash shell Whenever i declare an array, and then using sqlplus, i am getting sqlplus error and return code 127. IFS="," declare -a Arr=($Variable1); SQLPLUS=sqlplus -s "${DBUSER}"/"${DBPASS}"@"${DBASE} echo "set head off ; " > ${SQLCMD} echo "set PAGESIZE 0 ;" >> ${SQLCMD}... (6 Replies)
Discussion started by: arghadeep adity
6 Replies

2. Shell Programming and Scripting

Sqlplus inside shell script writing to tmp file

Hi, facing an issue while calling sqlplus inside shell script. It for some reason goes to tmp file to write something and i get error as permission denied as i dont have access there. ANy idea why sqlplus writes in /tmp and how to change or stop this ? (2 Replies)
Discussion started by: rushikeshs
2 Replies

3. Shell Programming and Scripting

Use sqlplus statement inside case sentence

Hello, I have a problem. I want to launch a different sql queries for different shell parameter values, something like this. #/bin/bash case $1 in "A") sqlplus -s user/pass << SQL query A; SQL "B") sqlplus -s user/pass << SQL2 ... (3 Replies)
Discussion started by: Vares
3 Replies

4. Shell Programming and Scripting

Nested case inside awk

please let me know if the below code could be written efficiently inside single awk case "$INP" in ksh) cat catalog | awk 'BEGIN {FS=",";} { print $2 } END {}' ;; pset) cat catalog | awk 'BEGIN {FS=",";} { print $3 } END {}' ;; dml) cat catalog | awk 'BEGIN {FS=",";} {... (2 Replies)
Discussion started by: cvsanthosh
2 Replies

5. Shell Programming and Scripting

nested if else -error

HI everyone, I am not able to find error in the script, when i run the script till line No. 20 i.e, read var4 everything runs fine. After that the script exits out. #!/bin/bash echo -e "Want dryrun OR merge: \n " read var1 if ] ; then echo -e "\n Please select from the given... (10 Replies)
Discussion started by: rishi.aradhya
10 Replies

6. Shell Programming and Scripting

how to use sqlplus command inside for loop

I tried this: for region in 'raj' 'kt' 'kol' 'krl' 'chn' 'dl' 'hr' 'bih' 'ap' do sqlplus -s huw$region/`echo $region`huw#321@huw$region<<! set serveroutput on begin select count(*) from tcd_preferred_cust_201109 end; / exit; done but the error shows like: Syntax error at line 4 :... (1 Reply)
Discussion started by: deepakprasad29@
1 Replies

7. Red Hat

Repacking a file inside a java archive with nested .jars

Hello, I need to repack a file inside several java archives (nested .jar files) with or without overwrite. I am using a manual approach with mc, but it's painfully slow progress. For example I want to refresh a file deep inside a java archive (with nested .jar files): I have a java... (0 Replies)
Discussion started by: Laurentiu
0 Replies

8. Shell Programming and Scripting

Error while using sqlplus command inside 'if' condition in an unix shell script

Hi all, I am using the below given sqlplus command in my unix script to invoke a stored procedure which returns a value .It works fine. RET_CODE=$(/opt/oracle/product/10.2.0.4.CL/bin/sqlplus -S $USER/$PASSWD@$DB_NAME <<EOF EXEC MY_PKG.MY_SP (:COUNT); PRINT COUNT; commit; ... (6 Replies)
Discussion started by: Shri123
6 Replies

9. Shell Programming and Scripting

nested double quota and white space inside variable

I have a question about nested double quotes. Any help is appreciated. Here are my commands on Mac OS. # string="Ethernet \"USB Ethernet\" \"Bluetooth DUN\" AirPort FireWire \"Bluetooth PAN\"" # echo $string Ethernet "USB Ethernet" "Bluetooth DUN" AirPort FireWire "Bluetooth PAN" #... (3 Replies)
Discussion started by: lindazhou
3 Replies

10. Shell Programming and Scripting

comment and Uncomment single task out of multiple task

I have a file contains TASK gsnmpproxy { CommandLine = $SMCHOME/bin/gsnmpProxy.exe } TASK gsnmpdbgui { CommandLine = $SMCHOME/bin/gsnmpdbgui.exe I would like to comment and than uncomment specific task eg TASK gsnmpproxy Pls suggest how to do in shell script (9 Replies)
Discussion started by: madhusmita
9 Replies
Login or Register to Ask a Question