Sponsored Content
Full Discussion: Error in the script
Top Forums Shell Programming and Scripting Error in the script Post 302654885 by Corona688 on Tuesday 12th of June 2012 11:08:53 AM
Old 06-12-2012
Also, you didn't need to attach the file, you could have posted it, in code tags, like this:

Code:
#!/bin/ksh


. ~/.profile
export FILE_DT=`date +%b%d-%Y-%H%M%S`
export FILE_PREFIX="process_extract"
export PROCESS_EXTRACT_DIR=$DATA_HOME/process/extract
export PROCESS_EXTRACT_AR_DIR=$DATA_HOME/process/archive
export PROCESS_EXTRACT_FILE="$FILE_PREFIX_$FILE_DT.txt"
export PROCESS_LOG_DIR=$LOG_HOME/process_extract
export PROCESS_LOG=$PROCESS_LOG_DIR/PROCESS_EXTRACT_log.$FILE_DT

PROC_STATUS="0"
#SFTP_DELAY=180  # how long to sleep; 180 = 3 minutes

if test -r $PROCESS_EXTRACT_DIR/$FILE_PREFIX*.txt
then                                    
    rm -f $PROCESS_EXTRACT_DIR/$FILE_PREFIX*.gz
    /usr/contrib/bin/gzip $PROCESS_EXTRACT_DIR/$FILE_PREFIX*.txt
fi                                      

# LOG FILE CLEAN UP
if test -r $PROCESS_LOG_DIR/PROCESS_EXTRACT_log.*
then                                    
    rm -f $PROCESS_LOG_DIR/PROCESS_EXTRACT_log*.gz
    /usr/contrib/bin/gzip $PROCESS_LOG_DIR/PROCESS_EXTRACT_log.*
fi                                      

#  REDIRECT STDOUT STDERR

exec 1>$PROCESS_LOG
exec 2>$PROCESS_LOG

echo "__________"
echo "executing $SCRIPTS/PROCESS_EXTRACT.ksh on $ORACLE_SID"
echo 'START DATE/TIME:  ' `date +%b%d-%Y-%H:%M:%S`

# CALL STORED PROCEDURE
if [ "$PROC_STATUS" = "0" ]
then
    echo "calling stored procedure to create csv file"
    $SCRIPTS_SQL/process_extract.sql > $PROCESS_LOG_DIR/process_extract.out

    # CHECK RETURN FOR SUCCESS
    wait
    if grep 'PROCESS_EXTRACT_FAILURE' $PROCESS_LOG_DIR/process_extract.out || grep 'ORA-'  
$PROCESS_LOG_DIR/process_extract.out
    then
        # on error notify operator 
        echo `date +%b%d-%Y-%H:%M:%S`" CMS/PROCESS EXTRACT PL/SQL PROCESS ERROR"
	 mailx -s "CRITICAL - $ORACLE_SID:  CMS/PROCESS EXTRACT PROCESS FAILURE" $IT_ML_LST < $PROCESS_LOG
        PROC_STATUS="1"
    else
        echo `date +%b%d-%Y-%H:%M:%S`" CMS/PROCESS EXTRACT PL/SQL PROCESS SUCCESS"
        #sleep $SFTP_DELAY  # wait for file permissions job to run

     fi
fi

# VERIFY THAT THE FILE IS PRESENT AND FIND OUT ITS SHORT NAME
if [ "$PROC_STATUS" = "0" ]
then
    echo 'Getting a list of CSV files'
    file_list=`ls $PROCESS_EXTRACT_DIR/*.csv | sed 's!.*\/\([^\/]*\).*!\1!g'`
fi

# Declare SFTP parameters
export USER_PORT="Port=12314"
export USER_HOST=$USER@$FTP_HOST
export UPLOAD_DIR=$PROCESS_UPLOAD_DIR
export FTPSCRIPT="process_extract_ftpscript.txt"
export HPOV_DIR="/opt/OV/bin/OpC"
 
# PROCESS PROCESS EXTRACT FILES
for PROCESS_EXTRACT_FILE in $file_list
do

   ux2dos $PROCESS_EXTRACT_FILE
   echo 'ux2dos executed'

   echo 'processing file  ' $PROCESS_EXTRACT_FILE
   
  # Create SFTP script to send process extract files to upload directory#
  echo 'create sftp script'
  print "cd $UPLOAD_DIR" > $SCRIPTS/ftp/$FTPSCRIPT
  print "lcd $PROCESS_EXTRACT_DIR" >> $SCRIPTS/ftp/$FTPSCRIPT
  if [ -s $PROCESS_EXTRACT_DIR/$PROCESS_EXTRACT_FILE ]
  then

    print "put $PROCESS_EXTRACT_FILE $PROCESS_EXTRACT_FILE" >> $SCRIPTS/ftp/$FTPSCRIPT
  else 
    echo 'Unable to locate file '$PROCESS_EXTRACT_FILE
  fi
  print "bye" >> $SCRIPTS/ftp/$FTPSCRIPT

  # Running FTPSCRIPT
  echo 'Calling FTP script for ' $PROCESS_EXTRACT_FILE
  cd $DATA_HOME
  wait
  if [ "$PROC_STATUS" = "0" ]
  then
    sftp -b $SCRIPTS/ftp/$FTPSCRIPT -o $USER_PORT $USER_HOST
    sftp_rc=$?
    echo "ftp return code is " $sftp_rc
    if [ "$sftp_rc" = "0" ]
    then
      echo `date +%b%d-%Y-%H:%M:%S`" $PROCESS_EXTRACT_FILE  file FTP TO EFT LOCATION SUCCESS"
      # Find out the name of the archived file
      export EXTR_FN_DT=`date +%b%d-%Y-%H:%M:%S`
      IDX=`expr index $PROCESS_EXTRACT_FILE 20`
      IDX=`expr $IDX - 1`
      PROCESS_EXTRACT_FILE_AR=`expr substr $PROCESS_EXTRACT_FILE 1 $IDX`$EXTR_FN_DT
    
 	 # ARCHIVE THE FILE
   	    mv $PROCESS_EXTRACT_DIR/$PROCESS_EXTRACT_FILE $PROCESS_EXTRACT_AR_DIR/$PROCESS_EXTRACT_FILE_AR
	      /usr/contrib/bin/gzip $PROCESS_EXTRACT_AR_DIR/$PROCESS_EXTRACT_FILE_AR
    else
      echo `date +%b%d-%Y-%H:%M:%S`"$PROCESS_EXTRACT_FILE file FTP TO EFT LOCATION FAILURE"
      PROC_STATUS="1"
      cat $BATCH_LOG | mailx -s "PROCESS EXTRACT PROCESS FAILURE ON $ORACLE_SID"  $PROCESS_ML_LST
    fi
  else
    echo 'Stopping FTP as there was an error'
  fi

  # REMOVE FTP SCRIPT
  #rm $SCRIPTS/ftp/$FTPSCRIPT
  STOPFLAG="1"

done

echo 'ready to check overall process and do clean-up'
echo "PROC_STATUS is " $PROC_STATUS
echo 'STOP DATE/TIME:  ' `date +%b%d-%Y-%H:%M:%S`
echo ' '



# CHECK OVERALL PROCESS

if [ "$PROC_STATUS" = "1" ]
then
    # notify operator
    echo `date +%b%d-%Y-%H:%M:%S`" CMS/PROCESS EXTRACT PROCESS FAILURE"
    #mailx -s "$ORACLE_SID:  CMS/PROCESS EXTRACT PROCESS FAILURE" $IT_ML_LST < $PROCESS_LOG
    #echo "Please refer to e-mail or log for more info." > ./tmp_mail_msg
    #mailx -s "$ORACLE_SID:  CMS/PROCESS EXTRACT PROCESS FAILURE" $IT_ML_LST_PAGER < ./tmp_mail_msg
   # mailx -s "CRITICAL - $ORACLE_SID:  CMS/PROCESS EXTRACT PROCESS FAILURE" $IT_ML_LST < $PROCESS_LOG
    echo "Please refer to e-mail or log for more info." > ./tmp_mail_msg
    ###mailx -s "CRITICAL - $ORACLE_SID:  CMS/PROCESS EXTRACT PROCESS FAILURE" $IT_ML_LST_PAGER < ./tmp_mail_msg
elif [ "$PROC_STATUS" = "2" ]
then
    # no action for empty file
    :
else
    # log success
    echo `date +%b%d-%Y-%H:%M:%S`" CMS/PROCESS EXTRACT PROCESS SUCCESS"
  #  mailx -s "$ORACLE_SID:  CMS/PROCESS EXTRACT PROCESS SUCCESS" $IT_ML_LST < $PROCESS_LOG
    echo "File $PROCESS_FILE has been created and transmitted." > ./tmp_mail_msg
    ###mailx -s "$ORACLE_SID:  EXTRACT  PROCESS" $ENMASSE_BS_ML_LST < ./tmp_mail_msg
fi                           

# GET DBMS_OUTPUT RESULTS

cat $PROCESS_LOG_DIR/process_extract.out >> $PROCESS_LOG
#rm -f $PROCESS_LOG_DIR/process_extract.out
rm -f ./tmp_mail_msg

exit

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

2. Shell Programming and Scripting

Script with error output but continuation in script?

I have written a basic fetching script. The script logs into an FTP site, downloads a .zip file, then unzips and moves the files to the necessary folders, then deletes them, etc. The problem I have is if one of the files no longer exists on the FTP site or another part of the script fails, then... (3 Replies)
Discussion started by: daem0n
3 Replies

3. Windows & DOS: Issues & Discussions

Error opening script file - location error

Hello, I know nothing about UNIX, ftp, etc. I am building an excel VBA macro which calls a .bat file. I've taken a pre-existing batch file and am trying to modify it to fit my purposes. I would be very grateful for some assistance. Here is my .bat file: echo off set... (9 Replies)
Discussion started by: starcraftbud
9 Replies

4. Shell Programming and Scripting

How to grep sql error in shell script and exit the script?

I need help in the following script. I want to grep the sql errors insert into the error table and exit the shell script if there is any error, otherwise keep running the scripts. Here is my script #!/bin/csh -f source .orapass set user = $USER set pass = $PASS cd /opt/data/scripts echo... (2 Replies)
Discussion started by: allinshell99
2 Replies

5. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

6. UNIX for Dummies Questions & Answers

Re: Script Error [syntax error at line]

Hi , I Have Written A Simple Script To Check Greatest Of '2' Number When Execuating The Script I Am Getting The Below Error SP11: if:not found SP11: line 4:syntax error at line 5:'then' unexpexted And The Program I Have Wrriten For This #!bin/ksh echo "Enter Two Numbers"... (3 Replies)
Discussion started by: anudeepkumar123
3 Replies

7. Shell Programming and Scripting

Error in calling a shell script from another script

HI, We are using two shell scripts, script.sh,env.sh, where env.sh will be called inside script.sh. The variable inside env.sh is used as $var in script.sh.But while running the script its not identifying that variable. Is there any permission needed to call a script inside another script. ... (3 Replies)
Discussion started by: banupriyat
3 Replies

8. Shell Programming and Scripting

Help with FTP Script which is causing "syntax error: unexpected end of file" Error

Hi All, Please hav a look at the below peice of script and let me know if there are any syntax errors. i found that the below peice of Script is causing issue. when i use SFTP its working fine, but there is a demand to use FTP only. please find below code and explain if anything is wrong... (1 Reply)
Discussion started by: mahi_mayu069
1 Replies

9. Shell Programming and Scripting

Calling shell script within awk script throws error

I am getting the following error while passing parameter to a shell script called within awk script. Any idea what's causing this issue and how to ix it ? Thanks sh: -c: line 0: syntax error near unexpected token `newline' sh: -c: line 0: `./billdatecalc.sh ... (10 Replies)
Discussion started by: Sudhakar333
10 Replies

10. Shell Programming and Scripting

Shell script with sql script error

Hi All when I execute from psql prompt, I get the result, when I try to automate using a shell script, the query is not working # `/usr/bin/psql -U postgres -d coba1 -c "select name from users where "Date" > current_date - 30;"` ERROR: column "Date" does not exist LINE 1: select... (2 Replies)
Discussion started by: srilinux09
2 Replies
All times are GMT -4. The time now is 12:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy