williebens 0 Light Poster

Hello All:

I would like to know how I should go about rotating files that end with a date stamp. This is the configuration I have to rotate my Apache access files, but it is not working:

/var/log/httpd/access_log.* {

compress

daily

rotate 1

copytruncate

missingok

notifempty

}


The files are created with a date extension like the ones below:

access_log.100810-00_00
access_log.092810-00_00

access_log.100510-00_00


I need to find to rotate them so that I get this:

access_log.00810-00_00.bz2
access_log.092810-00_00.bz2
access_log.100510-00_00.bz2

Since the above is not working, I am working on a script to make it happen, but I am having the following issues:.
This is what I have done so far. I have this script:

LOGDIR="/var/log/httpd"
BZIP=`whereis bzip2`
cd $LOGDIR
LISTACC=$(ls access*)
LISTERR=$(ls error*)

LISTACC1=$(ls access*.bz2)
LISTERR1=$(ls error*.bz2)

for files in $LISTACC $LISTERR
do
if [[ $files != *.bz2 ]] && [[ -f $files ]]
then
bzip2 $files
fi
done
for files1 in $LISTACC1 $LISTERR1
do
#if [[ $files1 == *.bz2 ]]
#then
#echo "files ones are: $files1"
$newfilenames=`echo $files1 | sed 's/bz2/1.bz2/g'`
#echo "the new names are $newfilenames"
#mv $files1 $newfilenames
#fi
done

However, for the second for loop, it is not working. These are my log files:

access_log.073010-00_00.bz2
access_log.082810-00_00.bz2
access_log.083010-00_00.bz2
access_log.bz2
error_log.042310-00_00.bz2
error_log.070910-00_00.bz2
error_log.080510-00_00.bz2
error_log.bz2

When I run the script, it gives me and error as follows:

[root@scripts willie]# bash newnanme.sh
access_log.073010-00_00.1.bz2
access_log.073010-00_00.2.bz2
access_log.073010-00_00.3.bz2
newnanme.sh: line 38: =access_log.073010-00_00.1.bz2: command not found
newnanme.sh: line 38: =access_log.082810-00_00.1.bz2: command not found
newnanme.sh: line 38: =access_log.083010-00_00.1.bz2: command not found
newnanme.sh: line 38: =access_log.1.bz2: command not found
newnanme.sh: line 38: =error_log.042310-00_00.1.bz2: command not found
newnanme.sh: line 38: =error_log.070910-00_00.1.bz2: command not found
newnanme.sh: line 38: =error_log.080510-00_00.1.bz2: command not found
newnanme.sh: line 38: =error_log.1.bz2: command not found
[root@scripts willie]#

I want the logs to be renamed to

access_log.073010-00_00.1.bz2
access_log.082810-00_00.1.bz2
access_log.083010-00_00.1.bz2
access_log.1.bz2
error_log.070910-00_00.1.bz2
error_log.080510-00_00.1.bz2

and so on.

Please someone guide me to fix this error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.