2008-11-17 7 views
0

Comme vous avez beaucoup de questions ou pas assez d'informations pour travailler avec, voici des informations exclusives et en tant que telles soyez prudent que vous le pouvez. La question - (s'il vous plaît se référer à si [$ 7 -eq "AAA"] ... alors déclaration - en gras) a un problème avec une sortie, où je ne peux que sortie/impression compte de «AAA» indépendamment de la variable entrant dans 'BBB' ou 'AAA'. Par conséquent, et en tant qu'erreur, le programme génère/imprime le compte de 'AAA'.Besoin de dépannage sous UNIX avec le programme de script shell et la commande IF..THEN

Encore une fois, dans cette situation, j'ai essayé de mon mieux d'expliquer à ceux qui sont disponibles et avertis. Merci.

----------------------------------------------------------------------- 
# Print the run date 
echo "**********************" 
echo " TALK Program " 
echo " Run Date " 
    date 
echo "**********************" 

#   DIRECTORIES/VARIABLES/PARAMETERS 

p1=$1 
p2=$2 
p3=$3 
p4=$4 
p5=$5 
p6=$6 
p7=$7 
p8=$8 

echo "***********************************************" 
echo "The parameteres are" 
echo "         " 
echo " Param 1 (Username/Password) = " 
echo " Param 2 (User account number) = "$2 
echo " Param 3 (Requestor name)  = "$3 
echo " Param 4 (Requestor ID)  = "$4 
echo " Param 7 (AAA or BBB)   = "$7 
echo " Param 8 (TALK Data Filename) = "$8 
echo "***********************************************" 

AREA1=$WILLS_TOP/bin      # Switch-variable points to GENEX bin dir 
AREA2=$WILLS_TOP/sql      # Switch-variable points to GENEX sql dir 

SQL_CTL=$AREA1/WILLSTALK.ctl    # Name of SQL*Load ctrl file     
SQL_VALID=$AREA2/WILLSTALK.sql   # Name of validation PL/SQL script 

FTP_BIN=/usr/local/bin     # Where ftp program is 
UNIX_GET=$FTP_BIN/ftpmget.sh    # Name of UNIX file get program 
UNIX_PUT=$FTP_BIN/ftpmput.sh    # Name of UNIX file put program 
UNIX_DEL=$FTP_BIN/ftpdel.sh    # Name of UNIX file delete program 

TEMP=/tmp         # Name of temp dir 

INPUT_DIR=/oracle/inbound     # For DVLP Where input file is comming from 
ARCHIVE_NT_DIR=/oracle/inbound/RFS_DVLP # For DVLP Modified on 2005 

OUTPUT_DIR=/oracle/outbound/    # Where output file is going to 
OUTPUT_UNIX_DIR=$OUTCSF/$$OUTLOG/   # Directory of where output is 
DES_NAME=${OUTPUT_UNIX_DIR}${OUT_FILE} # Where output is going to be 

USERACCNUM=$p2       # User Account Number 
USERNAME=$p5        # Username 
PASSWORD=$p6        # Password 
AAA_OR_BBB=$p7       # Either 'AAA' or default of 'BBB' 
DATAFILE_NAME=$p8       # Datafile name (NT) 
SERVER='172.........'      # Server (NT) 
LOG_DIR=$WILLS_TIP/log     # Path of log dir 
LOCAL_DIR=$WILLS_TIP/data     # Directory where file is at (UNIX) 
ARCHIVE_DIR=$WILLS_TIP/archive   # Directory for archive (UNIX) 
FILE_NAME=""        # File name (UNIX) 
FILE_TRAN_TYPE='ascii'     # File transfer type 

#***************************************************************************** 
#        MAIN PROCEDURE 
#***************************************************************************** 
if [ ! "$p7" ] 
then 
    echo "At least one MS Excel Update Data File must be entered !" 
    echo "No files were entered." 
    exit 1 
fi 

#---------------------------------------------------------------------- 
# Remove all MS Excel datafile in $GENEX_TOP/data directory if exist 
#---------------------------------------------------------------------- 
rm -f $WILLS_TIP/data/TALK* 

#-------- 
# FTP 
#-------- 
${UNIX_GET} $p5 $p6 $SERVER $INPUT_DIR $DATAFILE_NAME $LOCAL_DIR "" $TEMP $FILE_TRAN_TYPE 

if [ $? != 0 ] 
then 
    echo "The MS Excel Datafile(s) ftp has failed." 
    exit 1 
fi 

if [ ! -s $LOCAL_DIR/$p8 ] 
then 
    echo "FTP command executed, but MS Excel file(s) did not get copied." 
    exit 2 
fi 

#----------------------------------------- 
# SQL*Loads - New MS Excel file to load 
#----------------------------------------- 

for i in $LOCAL_DIR/$DATAFILE_NAME 
do 
    SQLOAD_DAT_FILE=`echo $i | sed "s/\// /g" | awk ' { print $NF } '` 

    SQLOAD_LOG_FILE=$SQLOAD_DAT_FILE.log   # Sqlload log file name 
    SQLOAD_BAD_FILE=$SQLOAD_DAT_FILE.bad   # Sqlload bad file name 

    if [ -s $LOG_DIR/$SQLOAD_BAD_FILE ] 
    then 
     rm -f $LOG_DIR/$SQLOAD_BAD_FILE # Remove prev. bad file, if such exists 
     echo "Previous bad file has been successfully removed." 
    else 
     echo "No bad file was identified and removed." 
     echo "Resume Normal Processing." 
    fi 

    echo $i 
    echo "Now loading datafile: $LOCAL_DIR/$SQLOAD_DAT_FILE" 

    #--------------------------------------------------------------- 
    sed "s/@USERACCNUM/$USERACCNUM/" $SQL_CTL > $TEMP/WILLSTAL.ctl # Changing '@USERACCNUM' 
    #--------------------------------------------------------------- 

    sqlldr userid=${p1} control=$TEMP/WILLSTALK.ctl \ 
      log=$LOG_DIR/$SQLOAD_LOG_FILE \ 
      bad=$LOG_DIR/$SQLOAD_BAD_FILE \ 
      data=$LOCAL_DIR/$SQLOAD_DAT_FILE 

    if test ! -s $LOG_DIR/$SQLOAD_BAD_FILE 
    then 
     tail -20 $LOG_DIR/$SQLOAD_LOG_FILE 
     echo "*** Done SQL*Loader Script ***" 
    else 
     echo "The SQL*Load for MS Excel Update file has FAILED due to BAD DATA." 
     echo "*** Exitting Script On Failure ***" 
     echo "*** Process is ready for NEXT LOAD! ***" 
     exit 1 
    fi 
done 

#---------------------------------------- 
#  To run a PL/SQL script 
#---------------------------------------- 
sqlplus -s $p1 @$SQL_VALID $AAA_OR_BBB 
if [ $? -ne 0 ] 
then 
    echo "The PL/SQL script for validation has FAILED." 
    exit 1 
fi 

#---------------------------------------------------------- 
# Now run SQL*Plus script Flat File Report After Updating 
#---------------------------------------------------------- 

sqlplus -s $1 <<EOF 

set echo off 
set heading off 
set space 0 
set newpage 0 
set pagesize 0 
set feed off 
set term on 

SPOOL $OUTCSF/$OUTLOG/l$4.log 

SELECT 'spool $OUTCSF/$APPLOUT/o$4.out' FROM dual; 

SPOOL OFF 

@$OUTCSF/$OUTLOG/l$4.log 

Select 'Run Date: '||to_char(sysdate, 'DD-MON-YYYY') From dual; 

Select '*************************************************************' From dual; 

SELECT 'ERRORS Found: '||count(*) 
    FROM gnx_rel_date_temp 
WHERE error_text IS NOT NULL; 

Select '--------------- ----------- ---------------------------------' From dual; 
Select 'TRX NUMBER  NEW DATE       ERROR TEXT' From dual; 
Select '--------------- ----------- ---------------------------------' From dual; 
SELECT trx_num||'|'||new_date||'|'||error_text 
    FROM will_rel_date_temp 
WHERE error_text IS NOT NULL; 

Select '*************************************************************' From dual; 

#------------- 
#---- AAA ---- 
#------------- 
if [ $7 -eq "AAA" ] then 
    SELECT 'Total AAA Updated: '||count(*)||' records'   
    FROM reldatetemp    
     ,allcustomers  
    WHERE trx_num = trx_no  
     AND error_text IS NULL  
     AND attr2 IS NOT NULL   
     AND attr2 = TO_CHAR(new_date,'YYYY/MM/DD HH24:MI:SS'); 
else 
    exit 0 
fi 
#--------------- 
#---- BBB ---- 
#--------------- 
if [ $7 -eq "BBB" ] then 
    SELECT 'Total BBB Updated: '||count(*)||' records'   
    FROM reldatetemp    
     ,allcustomers  
    WHERE trx_num = trx_no  
     AND error_text IS NULL  
     AND attr1 IS NOT NULL   
     AND attr1 = TO_CHAR(new_date,'YYYY/MM/DD HH24:MI:SS'); 
else 
    exit 0 
fi 

SPOOL OFF 
EOF 

#---------------------------------------------- 
# To delete the data files on NT 
#---------------------------------------------- 
${UNIX_DEL} $p5 $p6 $SERVER $INPUT_DIR $DATAFILE_NAME $TEMP 

mv $WILLS_TIP/data/$DATAFILE_NAME $WILLS_TIP/archive/. 

# All Done! 
echo "*** End of program *** " 

Répondre

2

quelque chose entre "sqlplus -s 1 < < $ EOF" et "EOF" est appelé "ici-doc" et destinés à la consommation par sqlplus. Vous ne pouvez pas vraiment vous attendre à ce que sqlplus comprenne le script shell sous la forme de "if [" $ 7 "-eq ....]".

Vous devriez faire tous les "ifs" en dehors de l'ici-doc et utiliser les résultats. Comme ceci:

if [ "$7" -eq "AAA" ] ; then 
    attr="attr2" 
elsif [ "$7" -eq "BBB" ] ; then 
    attr="attr1" 
else 
    echo "Bogus $7 - need AAA or BBB" 
fi 

.... 

sqlplus -s $1 <<EOF 
... 
SELECT 'Total $7 Updated: '||count(*)||' records'   
FROM reldatetemp    
    ,allcustomers  
WHERE trx_num = trx_no  
    AND error_text IS NULL  
    AND ${attr} IS NOT NULL   
    AND ${attr} = TO_CHAR(new_date,'YYYY/MM/DD HH24:MI:SS'); 
... 
EOF 

Faites attention à "$ {attr}" et lisez un didacticiel décent sur les scripts shell.

0

Comment le script peut continuer après ce code:

#------------- 
#---- AAA ---- 
#------------- 
if [ $7 -eq "AAA" ] then 
    SELECT 'Total AAA Updated: '||count(*)||' records'   
    FROM reldatetemp    
     ,allcustomers  
    WHERE trx_num = trx_no  
     AND error_text IS NULL  
     AND attr2 IS NOT NULL   
     AND attr2 = TO_CHAR(new_date,'YYYY/MM/DD HH24:MI:SS'); 
else 
    exit 0 
fi 

Si 7 $ = "AAA", puis exécutez la sélection, si 7 $ n'est pas = sortie "AAA" le script .....

Observe
K

+0

Cette partie est à l'intérieur ici-doc, donc "si" ne serait pas évalué – ADEpt

Questions connexes