Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 03-22-2005, 03:43 AM   #1
Registered: May 2002
Location: Philly/So. Jersey
Distribution: ESXi CentOS Red-Hat Ubuntuu Solaris Debian
Posts: 85

Rep: Reputation: 15
(Bash Scripting) Another set of eyes please

Hi All,

I was doing some old log clean up with this script I wrote and this morning it is barfing with the following error:

me@server:/var/log/apache/oldlogs# ./ default 2
./ line 49: syntax error: unexpected end of file

Script is as follows (yes I know its ugly but I don't script as much as I'd like...)


# Did I get any parameters?
if if [ ! $1 ] 
		echo "  "
		echo "  "
		echo "  "
		echo "I need some parameters to work with!"
		echo "  command syntax:"
		echo "  "
		echo "  ./ logname number"
		echo "  "
		echo "  "
		echo "  "		
		exit 2

echo $full_target
echo $compressed_target

gunzip -d $compressed_target

tail -n1 $full_target | awk '{ 
print $2 "\t" $3 "\t" $5
month = $2
day = $3
year = substr($5,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 ".error-" year month day ".log"
}' filename=$target_file | xargs -i mv $full_target /mnt/bigd/oldlogs/{}
It's sister script (the one that works with access.log) works just fine and they are almost identical (with the exception of the field layout). I've looked at this for a bit this morning but can't find the bug. I think I've looked at the code too long and need another set of eyes...

Your assistance appreciated!

Old 03-22-2005, 04:06 AM   #2
LQ Newbie
Registered: Mar 2005
Distribution: Debian GNU/Linux
Posts: 9

Rep: Reputation: 0
line 5: double "if"

The following command help you to debug bash scripts:
bash -x
Old 03-22-2005, 04:07 AM   #3
Senior Member
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145

Rep: Reputation: 51
If my memory doesn't fail you have to append a \ at the end of the line to tell bash you're continuing a command between lines, like:
tail -n1 $full_target | awk '{ 
print $2 "\t" $3 "\t" $5 \
month = $2 \
day = $3 \
Old 03-22-2005, 04:14 AM   #4
Registered: May 2002
Location: Philly/So. Jersey
Distribution: ESXi CentOS Red-Hat Ubuntuu Solaris Debian
Posts: 85

Original Poster
Rep: Reputation: 15
Thanks a bunch cate!

That was it... Definitely needed a fresh set of eyes for that one. The tip on the -x is also appreciated. Will work with that some more!

gbonvehi: Actually once the awk segment of the script is invoked, the '{ }' acts as the sort of 'global' container for any text within. Helps with the readability...


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
Bash scripting JonCooperUK Programming 3 03-04-2004 08:55 PM
bash scripting -=MaGo=- Programming 16 08-30-2003 07:07 PM
Bash scripting kbeaver Programming 5 07-18-2003 08:35 PM
arghhh my eyes... How do you set refresh rate in Mandrake 9.0?? slovin Linux - General 4 09-29-2002 05:37 AM
AAAARGH! My eyes! My beautiful eyes! briancof Linux - Newbie 3 11-27-2001 06:26 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:47 AM.

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