-   Programming (
-   -   (Bash Scripting) Another set of eyes please (

merana 03-22-2005 03:43 AM

(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... :scratch:

Your assistance appreciated!


cate@d.o 03-22-2005 04:06 AM

line 5: double "if"

The following command help you to debug bash scripts:

bash -x

gbonvehi 03-22-2005 04:07 AM

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 \

merana 03-22-2005 04:14 AM

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... :D

All times are GMT -5. The time now is 02:40 PM.