LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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-22-2005, 03:43 AM   #1
merana
Member
 
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# ./renerror.sh default 2
./renerror.sh: 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...)

Code:
#!/bin/bash
#

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

target_file=$1
target_number=$2
full_target=$target_file.error.log.$target_number
compressed_target=$full_target.gz
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!

Regards,
 
Old 03-22-2005, 04:06 AM   #2
cate@d.o
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:
Code:
bash -x script.sh
 
Old 03-22-2005, 04:07 AM   #3
gbonvehi
Senior Member
 
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145

Rep: Reputation: 53
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:
Code:
tail -n1 $full_target | awk '{ 
print $2 "\t" $3 "\t" $5 \
month = $2 \
day = $3 \
 
Old 03-22-2005, 04:14 AM   #4
merana
Member
 
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...
 
  


Reply



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

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

All times are GMT -5. The time now is 06:00 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