LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Unable to get the script up and running (https://www.linuxquestions.org/questions/linux-newbie-8/unable-to-get-the-script-up-and-running-4175501533/)

chethankrish 04-13-2014 08:56 AM

Unable to get the script up and running
 
Hi All,

I am very new to Linux and we are having a Checkpoint FW in our organization and we are using the below script to move the logs older than 5 days from our management server to an FTP server. When i try to run this script i am getting below error.

[Expert@Orkla-FW-Mgmt:0]# sh ftptest.sh
ftptest.sh: line 35: syntax error: unexpected end of file

Since there is no line-35 in the below script, i am confused on how to troubleshoot. Any ASAP help would be highly appreciated.


#!/bin/bash
#####################################################################
#The script is used to move log files under the directory #FWDIR/log#
#The logs files are move to directory destination ftp.orkla.com #
#####################################################################
#Variable declaration starts here
DESTSERV='ftp.orkla.com'
DATE=$(date +%b%d_%H_%M)
DIR='/var/log/opt/CPsuite-R76/fw1'
FILES2BMVD="$DIR/mvd_files$DATE.txt"
USER='****'
PASS='******'
THRESH='25'
USAGE=`df -HlP $DIR | grep -v ^Filesystem | tr -s ' ' | cut -d " " -f5 | cut -d "%" -f1`
NDIR=$DIR/$DATE
RDIR="ftp_data"
#Variable declaration ends here
#Start of Script
if [ $USAGE -ge $THRESH ];
then
mkdir -p $NDIR #Create a new directory
find $DIR -maxdepth 1 -type f -name "20*.log*" -mtime +5 -exec ls {} \; > $FILES2BMVD #list the files for copy
find $DIR -maxdepth 1 -type f -name "20*.log*" -mtime +5 -exec mv {} $NDIR/ \; # Move the files to be ftp'ied
ftp -i -n $DESTSERV <<EOF > $DIR/ftp_output.txt 2>&1
quote USER $USER
quote PASS $PASS
binary
lcd $NDIR
cd $RDIR
mput *
bye
EOF
fi
#End of Script

grail 04-13-2014 09:53 AM

Firstly, please use [code][/code] tags for code or data to make it more readable.

As for your problem, I would hazard a guess there is a missing set of quotes somewhere. Try placing the following as the second line of the script and check the output:
Code:

set -xv

chethankrish 04-13-2014 10:04 AM

Hi,

I added set -xv as second line and below is the output.

Quote:

[Expert@Orkla-FW-Mgmt:0]# sh ftptest.sh
#####################################################################
#The script is used to move log files under the directory #FWDIR/log#
#The logs files are move to directory destination ftp.orkla.com #
#####################################################################
#Variable declaration starts here
DESTSERV='ftp.orkla.com'
+ DESTSERV=ftp.orkla.com
DATE=$(date +%b%d_%H_%M)
date +%b%d_%H_%M
++ date +%b%d_%H_%M
+ DATE=Apr13_17_02
DIR='/var/log/opt/CPsuite-R76/fw1'
+ DIR=/var/log/opt/CPsuite-R76/fw1
FILES2BMVD="$DIR/mvd_files$DATE.txt"
+ FILES2BMVD=/var/log/opt/CPsuite-R76/fw1/mvd_filesApr13_17_02.txt
USER='***'
+ USER=****
PASS='***'
+ PASS=****
THRESH='25'
+ THRESH=25
USAGE=`df -HlP $DIR | grep -v ^Filesystem | tr -s ' ' | cut -d " " -f5 | cut -d "%" -f1`
df -HlP $DIR | grep -v ^Filesystem | tr -s ' ' | cut -d " " -f5 | cut -d "%" -f1
++ df -HlP /var/log/opt/CPsuite-R76/fw1
++ grep -v '^Filesystem'
++ tr -s ' '
++ cut -d ' ' -f5
++ cut -d % -f1
+ USAGE=38
NDIR=$DIR/$DATE
+ NDIR=/var/log/opt/CPsuite-R76/fw1/Apr13_17_02
RDIR="ftp_data"
+ RDIR=ftp_data
#Variable declaration ends here
#Start of Script
if [ $USAGE -ge $THRESH ];
then
mkdir -p $NDIR #Create a new directory
find $DIR -maxdepth 1 -type f -name "20*.log*" -mtime +5 -exec ls {} \; > $FILES2BMVD #list the files for copy
find $DIR -maxdepth 1 -type f -name "20*.log*" -mtime +5 -exec mv {} $NDIR/ \; # Move the files to be ftp'ied
ftp -i -n $DESTSERV <<EOF > $DIR/ftp_output.txt 2>&1
ftptest.sh: line 36: syntax error: unexpected end of file

allend 04-13-2014 10:19 AM

Perhaps there is a trailing space after the EOF?
The code seems to working until the here-document redirection.

chethankrish 04-13-2014 10:29 AM

Hi,

Thanks for your reply, but i am very sure that there is no trailing space after EOF. I am having issues editing this code in vi. I am trying to edit it using "ESC" & hitting "Insert" with little luck. Any suggestions on how to delete this space(if at all it is in there) through vi ?

allend 04-13-2014 10:40 AM

Code:

bye
EOF
fi
#End of Script

Move to after the F in EOF and hit D (that is capital D) to delete to end of line in vi command mode.

grail 04-13-2014 10:55 AM

Just to confirm, this file was not written under Windows?

chethankrish 04-13-2014 04:24 PM

Hi All,

Managed to crack this myself. Removed few spaces and this made the script to work. Thank you for your time & support.

#!/bin/bash
#####################################################################
#The script is used to move log files under the directory #FWDIR/log#
#The logs files are move to directory destination ftp.orkla.com #
#####################################################################
#Variable declaration starts here
DESTSERV='ftp.orkla.com'
DATE=$(date +%b%d_%H_%M)
DIR='/var/log/opt/CPsuite-R76/fw1'
FILES2BMVD="$DIR/mvd_files$DATE.txt"
USER='***'
PASS='*****'
THRESH='80'
USAGE=`df -HlP $DIR | grep -v ^Filesystem | tr -s ' ' | cut -d " " -f5 | cut -d "%" -f1`
NDIR=$DIR/$DATE
RDIR="ftp_data"
#Variable declaration ends here
#Start of Script
if [ $USAGE -ge $THRESH ];
then
mkdir -p $NDIR #Create a new directory
find $DIR -maxdepth 1 -type f -name "20*.log*" -mtime +5 -exec ls {} \; > $FILES2BMVD #list the files for copy
find $DIR -maxdepth 1 -type f -name "20*.log*" -mtime +5 -exec mv {} $NDIR/ \; # Move the files to be ftp'ied
ftp -i -n $DESTSERV << EOF > $DIR/ftp_output.txt 2>&1
quote USER $USER
quote PASS $PASS
binary
lcd $NDIR
cd $RDIR
mput *
bye
EOF
fi
#End of Script

grail 04-14-2014 03:20 AM

Again, without the use of code tags we will have no idea what changes you have made :(


All times are GMT -5. The time now is 11:32 PM.