LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-13-2014, 09:56 AM   #1
chethankrish
LQ Newbie
 
Registered: Apr 2014
Posts: 4

Rep: Reputation: Disabled
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
 
Old 04-13-2014, 10:53 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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
 
1 members found this post helpful.
Old 04-13-2014, 11:04 AM   #3
chethankrish
LQ Newbie
 
Registered: Apr 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
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

Last edited by chethankrish; 04-13-2014 at 11:07 AM.
 
Old 04-13-2014, 11:19 AM   #4
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,430

Rep: Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349
Perhaps there is a trailing space after the EOF?
The code seems to working until the here-document redirection.
 
Old 04-13-2014, 11:29 AM   #5
chethankrish
LQ Newbie
 
Registered: Apr 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
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 ?
 
Old 04-13-2014, 11:40 AM   #6
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,430

Rep: Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349
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.
 
Old 04-13-2014, 11:55 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Just to confirm, this file was not written under Windows?
 
Old 04-13-2014, 05:24 PM   #8
chethankrish
LQ Newbie
 
Registered: Apr 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
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
 
Old 04-14-2014, 04:20 AM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to scp files while running shell script through crontab idhillon77 Ubuntu 4 06-15-2012 11:59 AM
Shell Script to start a program either not running or kill if running avataratar Linux - Newbie 1 03-29-2012 03:45 AM
Difference between running script (.sh) from .bash_profile and running from login dsimha Linux - General 4 01-17-2012 11:06 AM
Shell Script: Getting signal handlers to work when running an application by script pkjss Programming 4 09-14-2011 05:23 AM
i get an error message running php script inside a cgi script. repolona Linux - Software 0 02-22-2007 10:10 PM


All times are GMT -5. The time now is 12:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration