LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-24-2005, 06:00 AM   #1
merana
Member
 
Registered: May 2002
Location: Philly/So. Jersey
Distribution: ESXi CentOS Red-Hat Ubuntuu Solaris Debian
Posts: 85

Rep: Reputation: 15
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!

Last edited by merana; 03-24-2005 at 06:01 AM.
 
Old 03-24-2005, 06:38 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
A ';' is missing in :
Code:
if [ "$target_file" != "$old_targetfile" ] then
it should be
Code:
if [ "$target_file" != "$old_targetfile" ]; then
 
Old 03-24-2005, 06:47 AM   #3
merana
Member
 
Registered: May 2002
Location: Philly/So. Jersey
Distribution: ESXi CentOS Red-Hat Ubuntuu Solaris Debian
Posts: 85

Original Poster
Rep: Reputation: 15
Nice. That got it! Thank Keefaz!
 
  


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
syntax error in C ++ mshinska Programming 3 10-07-2005 04:53 PM
Many errors when 'make'ing (example: error: syntax error before `::' token) darkblade Linux - Software 5 03-02-2005 03:00 PM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM
Where's the syntax error tamtam Programming 2 07-24-2004 09:07 AM
ERROR running make when installing Nvidia drivers (syntax error) randyriver10 Linux - Software 5 02-21-2004 04:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:32 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
Open Source Consulting | Domain Registration