Gettting error while executing script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Gettting error while executing script
# 1  
Old 11-23-2016
Gettting error while executing script

getting error as below while executing script in linux.

OS version:
Code:
Linux VGP-3GPSDB-LX 3.10.0-514.el7.x86_64 #1 SMP Wed Oct 19 11:24:13 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux

Code:
./imxtract.sh: line 395: unexpected EOF while looking for matching ``'
./imxtract.sh: line 402: syntax error: unexpected end of file

below is my script code , please assist to rectify the error.
Thanks in advance.


Code:
#!/bin/sh

. $HOME/.oraenv
. $HOME/.fisenv
CPDEVTSDEBUG="/tmp/CPDevts.debug"
CPDCSTADEBUG="/tmp/CPDcsta.debug"
CPDCSTFDEBUG="/tmp/CPDcstf.debug"
DATESTMP="`date '+%Y%m%d%H%M%S'`"
FILEDATE="`date '+%Y%m%d'`"
GPSTMP="/home/amp/tmp/"
WORKPATH="/tmp/"
CPDEVTSSEQ="CPDevts.seq"
CPDCSTASEQ="CPDcsta.seq"
CPDCSTFSEQ="CPDcstf.seq"
orasid="gpsu"
SQLLOGIN="`cat /home/amp/admin/sqlsec`"
pnum=1
pflag=0


# Funtion to display usage message #
#----------------------------------#
usagemsg ()
{
echo "Usage:"
echo "\tERROR!! No parameters are provided or parameters provided are incorrect."
echo ""
echo "\tValid parameters are as below:"
echo "\t\t./imxtract.sh -f {CPDevts|CPDcsta|CPDcstf} <month> <year>"
echo "\t\t./imxtract.sh -f {CPDcsta|CPDcstf} <day> <month> <year>\n"
echo "\t -f      = feed type"
echo "\t <day>   = day in 2 digits format. This parameter does not apply to feedtype 'CPDevtsf' & 'CPDevtsa'"
echo "\t <month> = month in 2 digits format"
echo "\t <year>  = year in 4 digits format"
}

# Function to check the validity of day value #
#---------------------------------------------#
chkday ()
{
 dy=$1
 mm=$2
 yy=$3
 if [ $dy -lt 1 ]; then
	usagemsg
	exit
 fi
 i=`echo $mm | wc -c`
 if [ $i -ne 3 ]; then
 	mm=`echo $mm | awk '{print "0"$1}'`
 fi
 case $mm in
 	01|03|05|07|08|10|12) dd=31
        ;;
	04|06|09|11) dd=30
        ;;
	02) if [ `expr $yy % 4` -eq 0 ]; then
	       	   dd=29
	    else
	       	   dd=28
	    fi
        ;;
 esac
 if [ $dy -gt $dd ]; then
	echo "Invalid day!!\n"
	usagemsg
	exit 
 fi
}


# Function to check the validity of month value #
#-----------------------------------------------#
chkmonth ()
{
 mth=$1
 if [ $mth -lt 1 ]; then
	usagemsg
	exit
 fi
 if [ $mth -gt 12 ]; then
	usagemsg
	exit
 fi
}

# Function to check the validity of year value #
#----------------------------------------------#
chkyear ()
{
 yr=$1
 if [ $yr -lt 1900 ]; then
	echo "Year value is less than 1900!!\n"
	usagemsg
	exit
 fi
 if [ $yr -gt 2999 ]; then
	echo "Year value is greater than 2999!!\n"
	usagemsg
	exit
 fi
}

# Function to extract data #
#--------------------------#
getdata ()
{
DATAPATH=$1
DEBUGFILE=$2
SEQFILE=$3
SQLCMD=$4
EFFDATE=$5
# Assigning sequence number #
#---------------------------#
if [ -f $DEBUGFILE ];  then
        rm $DEBUGFILE
fi
c=`ls $GPSTMP| grep -x $SEQFILE | wc -l`
if [ $c -eq 1 ]; then
        lastseqnum=`cat $GPSTMP$SEQFILE`
elif [ $c -gt 1 ]; then
        echo "More than 1 sequence file exists at $GPSTMP. Please check with the System Administrator."
        exit
elif [ $c -eq 0 ]; then
        lastseqnum=0
fi
seqnum=`expr $lastseqnum + 1`

echo $seqnum > $GPSTMP$SEQFILE
cnt=`echo $seqnum | wc -c`
if [ $cnt -lt 6 ]; then
        i=`expr 5 - $cnt`
        while [ $i -ne -1 ]
        do
           seqnum=`echo 0$seqnum`
           i=`expr $i - 1`
        done
elif [ $cnt -gt 6 ]; then
	echo "Sequence number to be assigned to file has exceeded 5 digits. Please check with Application Admin." | tee > $DEBUGFILE
	echo "To reset the reset the sequence number to zero(0), remove the $GPSTMP$SEQFILE" | tee >> $DEBUGFILE
	seqnum=`expr $seqnum - 1`
	echo $seqnum > $GPSTMP$SEQFILE
	exit
fi
if [ $EFFDATE -ne $FILEDATE ]; then
	TIMESTMP="`echo $DATESTMP | cut -c9-14`"
	HEADERDATE=$EFFDATE$TIMESTMP
else
	HEADERDATE=$DATESTMP
fi
WORKFILE="$DATAPATH""GPS_$FEED"_"$DATESTMP"_"$seqnum"_"$pnum.tmp"
sqlplus "$SQLLOGIN" $SQLCMD $WORKFILE > $DEBUGFILE

# Exception to handle non-existence of working file
ls $WORKFILE > /dev/null 2>&1
if [ $? -ne 0 ]; then
	seqnum=`expr $seqnum - 1`
	echo $seqnum > $GPSTMP$SEQFILE
	echo "$WORKFILE is not created. Please check..." | tee >> $DEBUGFILE
	exit
fi

# Exception to handle Oracle sql error
cat $DEBUGFILE | grep ORA- > /dev/null 2>&1
if [ $? -eq 0 ]; then
	rm -f $WORKFILE
	seqnum=`expr $seqnum - 1`
	echo $seqnum > $GPSTMP$SEQFILE
	echo "Oracle error is found in $DEBUGFILE. Please check..." | tee >> $DEBUGFILE
	exit
fi

# Create .dat file with header and trailer inserted #
#---------------------------------------------------#
DATAFILE="`echo $WORKFILE | sed 's/.tmp$/.DAT/g'"
header="00GPS    $FEED$HEADERDATE$seqnum$pnum$pflag"
echo "$header" > $DATAFILE
row="`tail -2 $WORKFILE | sed '/^$/d' | sed 's/rows selected//g' | sed 's/\.$//g' | cut -d' ' -f1`"
sed '$d' $WORKFILE | sed '$d' | sed '/^$/d' >> $DATAFILE   #To delete the last line and blank line
reccnt="`echo $row`"
if [ "$reccnt" = "no" ]; then
        row=00000000
else
        cnt="`echo $row | wc -c`"
        if [ $cnt -lt 9 ]; then
                i=`expr 8 - $cnt`
                while [ $i -ne -1 ]
                do
                   row="`echo 0$row`"
                   i=`expr $i - 1`
                done
        fi
fi

trailer="99GPS    $row"
echo "$trailer" >> $DATAFILE
rm $WORKFILE

# FTP .dat file to IM-CARGO SAS Server #
# ------------------------------------ #
FTPSFILE="`echo $DATAFILE | cut -d"/" -f6`"
#sh /home/amp/fisbin/imftp.sh $FTPSFILE $DATAPATH
}


############################################
# Main Body                                #
############################################
# Check the validity of parameters entered #
#------------------------------------------#
if [ $# -eq 0 ]; then
        usagemsg
        exit 
fi
if [ $1 = "-f" ] && [ $# -eq 1 ]; then
	usagemsg
	exit
fi 
if [ $1 != "-f" ]; then
	usagemsg
	exit
fi
if [ $2 != "CPDevts" ] && [ $2 != "CPDcsta" ] && [ $2 != "CPDcstf" ]; then
	usagemsg
	exit
fi
if [ $2 = "CPDevts" ] && [ $# -ne 4 ]; then
	usagemsg
	exit
fi
if [ $2 = "CPDcsta" ] && [ $# -ne 5 ]; then
	if [ $# -ne 4 ]; then
		usagemsg
		exit
	fi		
fi
if [ $2 = "CPDcstf" ] && [ $# -ne 5 ]; then
	if [ $# -ne 4 ]; then
		usagemsg
		exit
	fi
fi
if [ $2 = "CPDevts" ] && [ $# -eq 4 ]; then
         chkmonth $3
	 chkyear $4 
fi
if [ $2 = "CPDcsta" ] && [ $# -eq 4 ]; then
	chkmonth $3
	chkyear $4
fi
if [ $2 = "CPDcstf" ] && [ $# -eq 4 ]; then
	chkmonth $3
	chkyear $4
fi
if [ $2 = "CPDcsta" ] && [ $# -eq 5 ]; then
	chkday $3 $4 $5
	chkmonth $4
	chkyear $5
fi
if [ $2 = "CPDcstf" ] && [ $# -eq 5 ]; then
	chkday $3 $4 $5
	chkmonth $4
	chkyear $5
fi

FEED=`echo $2 | tr '[a-z]' '[A-Z]'`
case $FEED in
	CPDEVTS) mm=$3
		  yy=$4
		  i=`echo $mm | wc -c`
		  if [ $i -ne 3 ]; then
			mm=`echo $mm | awk '{print "0"$1}'`
		  fi 
		  case $mm in
			01|03|05|07|08|10|12) dd=31
			;;
			04|06|09|11) dd=30
			;;
			02) if [ `expr $yy % 4` -eq 0 ]; then
			      	dd=29
			    else
			     	dd=28
			    fi
			;;
	 	   esac
		   DATAPATH="/home/amp/fisoutput/FLT_EVENT/"
		   HEFFDATE=$yy$mm$dd
		   DEBUGFILE="$CPDEVTSDEBUG"
		   SEQFILE="$CPDEVTSSEQ"
		   SQL="@CPDevts.sql $mm $yy"
		   getdata $DATAPATH $DEBUGFILE $SEQFILE "$SQL" $HEFFDATE
	;;
	CPDCSTA|CPDCSTF) if [ $# -eq 5 ]; then
				dd=$3 
		  	   	mm=$4
		  	   	yy=$5
				dy=$dd
			   else
				dy=1
				mm=$3
				yy=$4
		  	        i=`echo $mm | wc -c`
		  	        if [ $i -ne 3 ]; then
				     mm=`echo $mm | awk '{print "0"$1}'`
		  	        fi
			   	case $mm in
				   01|03|05|07|08|10|12) dd=31
				   ;;
				   04|06|09|11) dd=30
				   ;;
				   02) if [ `expr $yy % 4` -eq 0 ]; then
			        	   dd=29
				       else
			        	   dd=28
				       fi
				   ;;
			   	esac
			   fi
			   case $mm in
				01) mon="JAN"
				;;
				02) mon="FEB"
				;;
				03) mon="MAR"
				;;
				04) mon="APR"
				;;
				05) mon="MAY"
				;;
				06) mon="JUN"
				;;
				07) mon="JUL"
				;;
				08) mon="AUG"
				;;
				09) mon="SEP"
				;;
				10) mon="OCT"
				;;
				11) mon="NOV"
				;;
				12) mon="DEC"
				;;
			   esac
			   while [ $dy -le $dd ]
			   do 
		  	      c=`echo $dy | wc -c`
		  	      if [ $c -ne 3 ]; then
		                 dy=`echo $dy | awk '{print "0"$1}'`
		  	      fi 
			      if [ $FEED = "CPDCSTA" ]; then
				 DATAPATH="/home/amp/fisoutput/SITA_PRI_MAS/"
		  		 DEBUGFILE="$CPDCSTADEBUG"
		  		 SEQFILE="$CPDCSTASEQ"
		  		 SQL="@CPDcsta.sql $dy-$mon-$yy $dy/$mm/$yy"
			      else
				 DATAPATH="/home/amp/fisoutput/SITA_PRI_MSK/"
		  		 DEBUGFILE="$CPDCSTFDEBUG"
		  		 SEQFILE="$CPDCSTFSEQ"
		  		 SQL="@CPDcstf.sql $dy-$mon-$yy $dy/$mm/$yy"
			      fi
			      HEFFDATE="$yy$mm$dy"
			      getdata $DATAPATH $DEBUGFILE $SEQFILE "$SQL" $HEFFDATE
			      dy=`expr $dy + 1`
			   done
	;;
esac
###################################################################
# End of Main Body                                                #
###################################################################



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 11-24-2016 at 04:43 AM.. Reason: Added CODE tags, deleted duplicate err msg.
# 2  
Old 11-23-2016
Line 174 is missing a ` character:

Code:
DATAFILE="`echo $WORKFILE | sed 's/.tmp$/.DAT/g'"
                                                ^

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Error when executing script

Hi, I wrote this script to test if the output for DIR1 and DIR2 comes out as I want : #!/bin/bash DAY=$(date +%d) MONTH=$(date +%b) YEAR=$(date +%Y) DIR1=$($MONTH$YEAR"_Blast_BC01") DIR2=$($MONTH$YEAR"_Blast_BC15") echo $DIR1 echo $DIR2 This is the output I want for echo $DIR1 ... (12 Replies)
Discussion started by: anaigini45
12 Replies

2. UNIX for Dummies Questions & Answers

Error executing the script

I have the following script test.sh owned by dwdev account and group dwdev, the permissions on the script are as follows. -rw-r-x--- 1 dwdev dwdev 279 Sep 17 13:19 test.sh Groups: cat /etc/group | grep dwdev dwdev:x:704:dwdev dwgroup:x:725:dwdev writers:x:726:dwdev User: cat /etc/passwd |... (3 Replies)
Discussion started by: Ariean
3 Replies

3. Shell Programming and Scripting

Error executing date script

Hi, Seen below is a simple date script. #! /bin/ksh VL = `date +%m/%d` VL1 = `TZ=GMT+24 date +%m/%d` VL2 = `TZ=GMT+48 date +%m/%d` VL3 = `TZ=GMT+72 date +%m/%d` VL4 = `TZ=GMT+96 date +%m/%d` VL5 = `TZ=GMT+120 date +%m/%d` echo $VL echo $VL1 echo $VL2 echo $VL3 echo $VL4 echo... (2 Replies)
Discussion started by: jayadanabalan
2 Replies

4. Shell Programming and Scripting

Error executing script

Please delete de thread. Thanks. (10 Replies)
Discussion started by: Rodrih92
10 Replies

5. Shell Programming and Scripting

Error while executing a script

Hi Please assist. Im getting an error while execuing the script name d "cdsnd.basel.cd_new " as siiadm user. Thanks. siiadm> ls -l total 64 -rwxr-xr-x 1 siiadm sboadm 1004 Sep 17 2008 cdsnd.basel.cd -rwxr-xr-x 1 siiadm sapsys 998 Nov 16 09:14 cdsnd.basel.cd_new... (1 Reply)
Discussion started by: samsungsamsung
1 Replies

6. UNIX for Dummies Questions & Answers

[solved] Error Executing the script.

# cat SERVERNAMES 10.180.8.231 10.180.8.232 10.180.8.233 10.180.8.234 10.180.8.235 10.180.8.236 10.180.8.237 10.180.8.238 10.180.9.239 fn_Exit() { echo "Machine Doesnt exist" exit 1 #exit shell script } (2 Replies)
Discussion started by: pinga123
2 Replies

7. UNIX for Dummies Questions & Answers

Error Executing the script.

Hi , I m getting an error after executing the script. My script. Script is used to find out the date on 8 different machines(mentioned in SERVERNAMES file). I have added public key to avoid ssh password and ssh without password working fine. #!/bin/sh fn_VMFind() { Date=`ssh -t... (5 Replies)
Discussion started by: pinga123
5 Replies

8. Shell Programming and Scripting

Error while executing the below script

I am executing the below in telnet #!/usr/bin/ksh File1=simple.txt # The file to check LogFile=simple.log # The log file DelayMax=30 # Timeout delay Tolerance=2 # BEGIN ############################## while true do StampNow=$(date +%s)/60 # stamp in minutes ... (3 Replies)
Discussion started by: chinniforu2003
3 Replies

9. Shell Programming and Scripting

Error while executing a script

My script is as below : #!/bin/sh for line in `cat Results.txt` do FEILD1=`echo $line |awk -F"|" '{print $1}'` FEILD2=`echo $line |awk -F"|" '{print $2}'` FEILD3=`echo $line |awk -F"|" '{print $3}'` FEILD4=`echo $line |awk -F"|" '{print $4}'` echo "$FEILD1 $FIELD2 $FIELD3 $FIELD4" done ... (15 Replies)
Discussion started by: shwetainnani
15 Replies

10. Shell Programming and Scripting

error while executing the script

Hello I am executing the following script nawk 'NR == 1 || substr($0,63,5) ~ /H... / && \ _++ == 2 { fn && close(fn); fn = "part_" ++c; _ = 1 } { print > fn }' sample.dat When i execute as it is it is executing fine. but when i execute the whole script as a single line like below ... (2 Replies)
Discussion started by: dsdev_123
2 Replies
Login or Register to Ask a Question