Link to home
Start Free TrialLog in
Avatar of bowemc
bowemc

asked on

FTP scripting error - line 267: syntax error: unexpected end of file

Hi,

The below lines are throwing the eblow error in my shell script on Linux. It worked previously which is what puzzles me!

 ftp -v -n $CONQUEST_FTP_HOST >> $LOG_PATH 2>> $LOG_PATH <<-END_SCRIPT
                user $CONQUEST_FTP_USER $CONQUEST_FTP_PASS
                lcd $LOG_KPI_DIR
                put $CSV_FILENAME $FTP_CSV_NAME
                quit
                END_SCRIPT


ERROR: line 267: syntax error: unexpected end of file
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Has the file been reformatted?

The END_SCRIPT lines needs to start at the left-hand side of the file, and not be indented.
Ah, didn't spot the "-" after the << (I think my font is too small!).

It *should* work, unless you are using an old shell whcih doesn't support <<-.
how you run the script?

can you run the script with

bash -x scriptname

and post the output?

It could be than one of the variables is not set or that you face problems with one of the ftp commands
Avatar of bowemc
bowemc

ASKER

I've replaced "-" with a " " blank caharacter and the same effect

omarfarid, below is the output of your command. It's the same as when I run ./edge_kpi.startup

bash-3.00$ bash -x edge_kpi.startup
edge_kpi.startup: line 267: syntax error: unexpected end of file
you just posted the error, can you post fiew lines before and after that? what is line 267 in your script?
Avatar of bowemc

ASKER

267 is the last line of the script

The last few line are:
#########################
####  MAIN (METHOD): ####

PWD=`pwd`
ARG1=$1
DAY=`date +%a`

if [ -f $PWD/edge_kpi.properties ] ; then
   . $PWD/edge_kpi.properties
else
   echo "${0}: Cannot load $PWD/edge_kpi.properties . Quitting." >&2
   exit 1
fi

LOG_KPI_DIR=$PWD
LOG_FILE=edgeKPI.$(date +"%Y%m%d").log
LOG_PATH=$LOG_KPI_DIR/$LOG_FILE

if [ "$DAY" = "Sat" -o "$DAY" = "Sun" ] && [ "$ARG1" = "" ]; then
        echo "Weekend: Script will not execute as an at-job."
else
        scriptLauncher
fi
emailLog
cd $PWD  # cd to the dir that the user started with, just for elegance

Open in new window

what I meant is that to post few lines before the error line from the output of

bash -x edge_kpi.startup

and the line 267
Avatar of bowemc

ASKER

bash-3.00$
bash-3.00$
bash-3.00$
bash-3.00$ clear
bash-3.00$ ./edge_kpi.startup
./edge_kpi.startup: line 267: syntax error: unexpected end of file
bash-3.00$
bash-3.00$
bash-3.00$
bash-3.00$ bash -x edge_kpi.startup
edge_kpi.startup: line 267: syntax error: unexpected end of file
bash-3.00$
bash-3.00$
bash-3.00$



and line 267 is


cd $PWD  # cd to the dir that the user started with, just for elegance
it looks like that your script is not complete and it complains before even executing any line. can you post the full script?

what the file $PWD/edge_kpi.properties contains?
Avatar of bowemc

ASKER

bash-3.00$ more edge_kpi.properties
##KPI Properties
export EDGE_EMAIL="xxx@xxx.com"
export CONQUEST_FTP_HOST=xxx.xx.xxx.com
export CONQUEST_FTP_USER=xxx
export CONQUEST_FTP_PASS=xxx@xxx.com


#SYSTEM ID
export CONQUEST_SYSTEM_ID=12



#!/bin/bash

function scriptLauncher()
{
        checkVars
        if [ "$STATUS" = "Unsuccessful" ]; then

        else
                setVars
                setupLogging
                echoConfig
                STATUS=Successful

                grepLogs
                genCSV
                sendFile
                removeFile
        fi

        echo $STATUS
}


function checkVars()
{

        if [ -z "$CONQUEST_FTP_HOST" ]; then
                STATUS=Unsuccessful
        fi

        if [ -z "$CONQUEST_FTP_USER" ]; then
                STATUS=Unsuccessful
        fi

        if [ -z "$CONQUEST_FTP_PASS" ]; then
                STATUS=Unsuccessful
        fi

        if [ -z "$EDGE_EMAIL" ]; then
                STATUS=Unsuccessful
        fi

}


function setVars()
{
        # ****** MISC VARS ******
        DATE=`date +"%Y%m%d"`

        # Check if date override was passed as argument
        if [ "$ARG1" != "" ]; then
                DATE=$(echo $ARG1 | sed 's/-//g')
                LOG_SUFFIX=".$ARG1"
        fi

        CSV_FILENAME=edgeKPI.$DATE.csv
        FTP_CSV_NAME=$CSV_FILENAME
        CSV_FILE=$LOG_KPI_DIR/$CSV_FILENAME

        # ****** LOG_ VARS (edge) ******
        LOG_EDGE=$LOG_KPI_DIR/../logs/edge.log$LOG_SUFFIX
        #************************
}


function setupLogging()
{
        if ! [ -d $LOG_KPI_DIR ]
        then
                mkdir $LOG_KPI_DIR
        fi

        if ! [ -f $LOG_PATH ]
        then
                touch $LOG_PATH
        fi

        # Find, then remove log files older than 30 days

        FOUND=`find $LOG_KPI_DIR/edgeKPI.*.log -mtime +30 -print | wc -l`

        if [ $FOUND -gt 0 ]
        then
               find $LOG_KPI_DIR/edgeKPI.*.log -mtime +30 -print | xargs rm -f
        fi
}


function echoConfig()
{
        if [ "$ARG1" != "" ]; then
                log "INFO:\t++Date override received. Business date will be set to $DATE.++"
        fi

        log "INFO:\t--Log file for edge set to: $LOG_EDGE --"
}



function log()
{
        echo -e "$(date +%H:%M:%S) $*" >> $LOG_PATH
}


function grepLogs()
{

        if  [ -f $LOG_EDGE ]; then
                EDGE_START_TIME=`grep "Startup took" ../logs/edge.log  | awk '{print $9}'`

        fi

        echoResult
}



function echoResult()
{
        log  "INFO:\t**Result from the 'grep' statements:
                        EdgE Startup: $EDGE_START_TIME"
}


function genCSV()
{
        log "INFO:\t**Currently: generating $CSV_FILE"
        if [ -f $CSV_FILE ]
        then
                log "INFO:\t**Deleting existing $CSV_FILE file."
                rm $CSV_FILE
        fi

        touch $CSV_FILE

        echo "id_system=$CONQUEST_SYSTEM_ID,id_param=EDGE_START_TIME,id_value=$EDGE_START_TIME,id_time_end=$DATE" >> $CSV_FILE

}



function sendFile()
{
        log "INFO:\t**Currently: FTP'ing $CSV_FILE"

        if [ -f $CSV_FILE ]     #CHECK IF the file exists then FTP
        then
                ftp -v -n $CONQUEST_FTP_HOST >> $LOG_PATH 2>> $LOG_PATH <<-END_SCRIPT
                user $CONQUEST_FTP_USER $CONQUEST_FTP_PASS
                lcd $LOG_KPI_DIR
                put $CSV_FILENAME $FTP_CSV_NAME
                quit
                END_SCRIPT

                if ! cat $LOG_PATH | tail -10 | grep "226 Transfer complete."
                then
                        log "ERROR:\tFile transfer did not complete successfully."
                        STATUS=Unsuccessful
                fi
        else
                log "ERROR: Could not transfer file - '$CSV_FILE' not found."
                STATUS=Unsuccessful
        fi
        log "INFO:\t**Currently: FTP complete"
}



function removeFile()
{
        #rm $CSV_FILE
        find -name "*.csv" -mtime +31 -exec rm {} \;
}



function emailLog()
{
        if [ "$STATUS" = "Unsuccessful" ]; then
                cd $LOG_KPI_DIR
                uuencode $LOG_FILE $LOG_FILE | mail -s "...EdgE KPI Scipt Log File: $STATUS..." "$EDGE_EMAIL"
        fi
}


#########################
####  MAIN (METHOD): ####

PWD=`pwd`
ARG1=$1
DAY=`date +%a`

if [ -f $PWD/edge_kpi.properties ] ; then
   . $PWD/edge_kpi.properties
else
   echo "${0}: Cannot load $PWD/edge_kpi.properties . Quitting." >&2
   exit 1
fi

LOG_KPI_DIR=$PWD
LOG_FILE=edgeKPI.$(date +"%Y%m%d").log
LOG_PATH=$LOG_KPI_DIR/$LOG_FILE

if [ "$DAY" = "Sat" -o "$DAY" = "Sun" ] && [ "$ARG1" = "" ]; then
        echo "Weekend: Script will not execute as an at-job."
else
        scriptLauncher
fi
emailLog
cd $PWD  # cd to the dir that the user started with, just for elegance

Open in new window

try to change

if [ "$DAY" = "Sat" -o "$DAY" = "Sun" ] && [ "$ARG1" = "" ]

to

if [ "$DAY" = "Sat" -o "$DAY" = "Sun" ] -a [ "$ARG1" = "" ]
Avatar of bowemc

ASKER

SAME

./edge_kpi.startup: line 267: syntax error: unexpected end of file
the problem is with the if statement. can you try removing the other part?

if [ "$DAY" = "Sat" -o "$DAY" = "Sun" ] ; then

I am not sure if this will work:

if [ ("$DAY" = "Sat" -o "$DAY" = "Sun")  -a  "$ARG1" = "" ] ; then
      
Avatar of bowemc

ASKER

same error

how do u know it's this line?

I've commented out this line and the error still happens.

The error goes away when i comment out the ftp part
how the script is edited? do you edit it on windows and upload to unix? it could be that you need to edit the script on unix using vi or you may i=upload it as text (if you use ftp) or you use dostunix tool to convert to unix text
Avatar of bowemc

ASKER

i've tried dos2unix
I was (sort of) right in the first place - it is the END_SCRIPT line (line 155 in ID:34969401 above).

The "<<-" removes tabs at the start of the line - you have spaces (as far as I can tell).

So either change the spaces in front of "END_SCRIPT" to tabs, or just move that text to the start of the line.
ASKER CERTIFIED SOLUTION
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial