Error in Shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error in Shell script
# 1  
Old 10-27-2010
Error in Shell script

Hello All,
I am newbe to scripting and have just taken over following script from previous developer. I am getting following error when running the script.
line 70: syntax error near unexpected token `do

Could some help me to rectify the error please. Thanks in advance for your help.

Code:
files_found=N
csv_file_type=NONE
client_code=NONE
client_file_id=NONE
#|--------------------------------------------
#|  Check arguments passed
#|---------------------------------------------
if [ $# = 0 ]
then
echo "===> ERROR : No parameters were passed to this Program <===="
exit
fi
#|--------------------------------------------
#|  Report arguments passed
#|---------------------------------------------
printf "\nThe arguments passed are: $*\n"
#|--------------------------------------------
#|  Check the apps password
#|---------------------------------------------
ret=`sqlplus -s $1 <<!! 
exit;
!!`

if [ -n "$ret" ] ; then
   echo $ret
   printf "===> ERROR : Incorrect password for oracle user apps <=== \n"                         
   exit 1
fi
#|--------------------------------------------
#|  Check the inbound file directory exists
#|---------------------------------------------

INBOUND_DIRECTORY=$5
echo $INBOUND_DIRECTORY
if [ ! -s "$INBOUND_DIRECTORY" ] ; then 
    printf "\n"
    printf "===> ERROR : The file directory $INBOUND_DIRECTORY cannot be found .... exiting.. <=== \n"
    printf "\n"
    exit 1
fi

#|-----------------------------------------------------
#| Function checks if second string is in first string
#|----------------------------------------------------
function checkstr
{   a=${1/$2*/}
    if [ "$1" = "$a" ]
    then
         return 1
    else
         return 0
    fi
}
#|---------------------------------------------------------------------------------------
#| Loop through files in directory
#|   Puts the file name in first field of each file line
#|   Grabs the file size and date into variables
#|---------------------------------------------------------------------------------------
for csv_dir_file in `ls /orautildir/FEXTESTC/*.csv 2>/dev/null`
do
  files_found=Y
  # Removes the directory from the file name by copying only last field
  # $NF is the last field and -F/ makes / the field separator
  csv_file=`echo "$csv_dir_file" |  awk -F/ '{ print $NF }'`
  #printf "File IS  $csv_file \n"   
  #Grabs first field, note -F sets the field separator to a comma
  first_field=`head -1 $csv_dir_file | awk -F, '{ print $1 }'`
   if [ "$csv_file" != "$first_field" ]
   then
      printf "File name and 1st field are different \n"
      sed "1,$ s/^/$csv_file,/" $csv_dir_file > $csv_dir_file.tmp #Replace Start of Line with Filename
      mv $csv_dir_file.tmp $csv_dir_file # " instead of ' allows $i to be a shell variable
   fi
   csv_file_dir=$INBOUND_DIRECTORY
   csv_file_date=`ls -l "$csv_dir_file" |  awk  '{ print $8" "$6"-"$7 }' `
   csv_file_size=`ls -l "$csv_dir_file" |  awk  '{ print $5 }' `
   printf "File found is $csv_file in directory is $csv_file_dir with date is $csv_file_date and size is $csv_file_size \n"
   printf "\n"
   #|-----------------------------------------------------
   #| Check the type of file from the file name
   #|-----------------------------------------------------
   filename=`echo "$csv_file" | tr 'A-Z' 'a-z'` # Brings everything to lowercase
   if checkstr "$filename" "err" # Checks if "error" is in the file name
   then
       csv_file_type=ERROR_FILE
       client_code=`head -1 $csv_dir_file | awk -F, '{ print $2 }' ` # Grabs client code from 2nd field
       client_file_id=`head -1 $csv_dir_file | awk -F, '{ print $4 }' ` # Grabs client file id from 4th field
   elif  checkstr "$filename" "feed"
   then
       csv_file_type=FEEDBACK_FILE
       client_code=`head -1 $csv_dir_file | awk -F, '{ print $2 }' ` # Grabs client code from 2nd field
       client_file_id=`head -1 $csv_dir_file | awk -F, '{ print $4 }' ` # Grabs client file id from 4th field
   else
       csv_file_type=NONE
       client_code=NONE
       client_file_id=NONE
   fi
   printf "The client file id is $client_file_id  \n "   
   #|-----------------------------------------------------
   #| Log the file's arrival in a table
   #|----------------------------------------------------
   if [ $csv_file_type != "NONE" ] && [ $client_code != "NONE" ] && [ $client_file_id != "NONE" ]
   then
         log=`sqlplus -s $1 <<EOS
            SET FEEDBACK OFF;
            WHENEVER SQLERROR EXIT;
            INSERT INTO XXFIN.FIPS_FILES(client_file_id,client_code,file_name,file_directory,file_date,file_size,file_type,status)
                  VALUES($client_file_id,$client_code,'$csv_file','$csv_file_dir','$csv_file_date',$csv_file_size,'$csv_file_type','NEW');
            COMMIT;
            EXIT;
         EOS`
         if [ -n "$log" ] ; then
            if checkstr "$log" "FIPS_FILES_UI"
            then
               printf " \n "
               printf "===================================================================== \n "
               printf "===> This file FILE $csv_file has ALREADY been loaded <=== \n "
               printf "===================================================================== \n "
               printf " \n "
            else
               printf "===> ERROR : Failed to insert into table FIPS_FILES for file $csv_file , Message $log \n "
               exit 1
            fi
         fi
   fi   
done
#|-----------------------------------------------------
#| Return error if no files were found in the directory
#|-----------------------------------------------------
if [ $files_found == "N" ]
then
  printf "\n"
  printf "===> ERROR No .csv files were found in directory $INBOUND_DIRECTORY <=== \n"
  printf "\n"
  exit 1
fi


---------- Post updated at 08:07 AM ---------- Previous update was at 07:25 AM ----------



Hi ,
Looks like something fundamental amiss. I tried to run this small script and still got the same error.
Code:
for var in A B C ;do
  echo "var is $var"
done

We are on Red Hat Enterprise Linux Server release 5.3 (Tikanga) Kernel \r on an \m

Last edited by Scott; 10-28-2010 at 08:00 AM.. Reason: rm colors - code tags please!
# 2  
Old 10-27-2010
What shell are you using?
# 3  
Old 10-27-2010
GNU bash, version 3.2.25(1)-release (i686-redhat-linux-gnu)
# 4  
Old 10-27-2010
How does this line work?
Code:
if checkstr "$filename" "err" # Checks if "error" is in the file name

Sorry if I ask silly things - I am debugging awkward SQL code and look here waiting for "inspiration"...
This User Gave Thanks to vbe For This Post:
# 5  
Old 10-27-2010
If directory has error file (i.e. if file name has err somewhere in it) then take client_code & client_file_id from it.
# 6  
Old 10-27-2010
I would start by testing my shell...
I it were something to do with environment, I would expect the system let you know...
Do you have another box to compare?
Can you try to execute simple loops with another shell to see what is going on?
(For so far, I see nothing suspect in code...but I only have a bash on AIX... and I have my SQL to solve...)
# 7  
Old 10-27-2010
Thanks a lot for taking a interest in this thread. I have only linux box to test the script. I have tried following simple loops but all failed with respective errors.

Code:
for n in {1..10}
do
   out=$(( $n % 2 ))
   if [ $out -eq 0 ]
   then
 echo "$n is even number"
   else
 echo "$n is ODD number"
   fi
done
 
'/test1.prog: line 2: syntax error near unexpected token `do
'/test1.prog: line 2: `do

x=1
while [ $x -le 5 ]
do
  echo "Welcome $x times"
  x=$(( $x + 1 ))
done

./test2.prog: line 6: syntax error near unexpected token `done'
./test2.prog: line 6: `done'
 
COUNTER=20
until [  $COUNTER -lt 10 ]
do
    echo COUNTER $COUNTER
    let COUNTER-=1
done
./test.prog: line 7: syntax error: unexpected end of file

It looks to me I am doing something fundamently wrong.

Last edited by Scott; 10-27-2010 at 03:40 PM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. Shell Programming and Scripting

Shell script error

Hi, I have the following table in MYSQL: (the structure looks broken in this forum but if you copy/paste it into notepad, it'll look right): +----------------------------+-----------------------+------+-----+---------+----------------+ | Field | Type |... (0 Replies)
Discussion started by: tezarin
0 Replies

7. UNIX for Dummies Questions & Answers

Shell Script Error

Sorry typo found please ignore (0 Replies)
Discussion started by: jazz8146
0 Replies

8. 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

9. UNIX for Dummies Questions & Answers

error in shell script

Hi, I have written a small shell script which logs into each oracle database on the server and displays whether it is in archivelog mode or not.. The script is as under: #!/bin/bash dblist=`ps -ef | grep smon | grep -v grep |cut -d'_' -f3` for ohome in $dblist; do sqlplus -s /nolog <<... (2 Replies)
Discussion started by: jalpan.pota
2 Replies
Login or Register to Ask a Question