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 |
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 |
Hi,
I added set -xv as second line and below is the output. Quote:
|
Perhaps there is a trailing space after the EOF?
The code seems to working until the here-document redirection. |
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 ? |
Code:
bye |
Just to confirm, this file was not written under Windows?
|
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 |
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. |