LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Ferreting out a syntax error. (https://www.linuxquestions.org/questions/programming-9/ferreting-out-a-syntax-error-305428/)

merana 03-24-2005 06:00 AM

Ferreting out a syntax error.
 
Need a hand again... :(

I'm trying to find out what the source of the following error is:

Quote:

user@server:/var/log/apache/oldlogs$ bash -x renaccess.sh
+ target_file=
+ old_targetfile=
renaccess.sh: line 83: syntax error near unexpected token `fi'
renaccess.sh: line 83: ` fi '
The code is as follows:

Code:


#!/bin/bash
# scriptname:        renaccess.sh
# by                        michaele
#
# target_file - Format: wiki
# target_number - Log Number
#
# Purpose
#
#        Uncompresses and then Renames logfiles from the archive filename format of:
#
#                fn_segment1.access.log.1.gz
#
#        to:
#
#                fn_segment1.access-YYMMDD.log
#
#        then moves them to:
#
#                /mnt/bigdrive/oldlogs/
#
# Did I get any parameters?
#if [ ! $1 ]
#        then
#                echo "  "
#                echo "  "
#                echo "  "
#                echo "I need some parameters to work with!"
#                echo "  command syntax:"
#                echo "  "
#                echo "  renaccess.sh logname"
#                echo "  "
#                echo "  "
#                echo "  "               
#                exit 2
#fi

target_file=
old_targetfile=

for target_file in $(ls *.access.* | awk -F . '{print $1}')
do

        if [ "$target_file" != "$old_targetfile" ] then
               
                for target_number in $(ls $target_file.access.* | awk -F . '{print $4}')
               
                do
                        full_target=$target_file.access.log.$target_number
                        compressed_target=$full_target.gz
                       
                        #echo $full_target
                        #echo $compressed_target
                       
                        echo "gunzip -d $compressed_target"
                       
                        tail -n1 $full_target | awk '{
                       
                        split ($4,dateparts,"/")
                       
                        month = dateparts[2]
                        day = substr(dateparts[1],2,2)
                        year = substr(dateparts[3],3,2)
                       
                        if(month == "Jan"){month="01"}
                        if(month == "Feb"){month="02"}
                        if(month == "Mar"){month="03"}
                        if(month == "Apr"){month="04"}
                        if(month == "May"){month="05"}
                        if(month == "Jun"){month="06"}
                        if(month == "Jul"){month="07"}
                        if(month == "Aug"){month="08"}
                        if(month == "Sep"){month="09"}
                        if(month == "Oct"){month="10"}
                        if(month == "Nov"){month="11"}
                        if(month == "Dec"){month="12"}
                       
                        if(length(day) == 1){day="0" day}
                        print filename ".access-" year month day ".log"
                        }' filename=$target_file | xargs -i echo "mv $full_target /mnt/bigdrive/oldlogs/{}"
                done
       
        fi
       
        old_targetfile = $target_file

done

I wonder if the "if" statements in the awk segment are causing the error?

Help appreciated!

keefaz 03-24-2005 06:38 AM

A ';' is missing in :
Code:

if [ "$target_file" != "$old_targetfile" ] then
it should be
Code:

if [ "$target_file" != "$old_targetfile" ]; then

merana 03-24-2005 06:47 AM

Nice. That got it! Thank Keefaz! :D


All times are GMT -5. The time now is 07:20 AM.