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,