deepakjena_2003
asked on
Apache Log Rotation
Hi,
I am facing lots of problem due to heavy logs generated by my Webserver.
I am using the following shell script to rotate the logs...but it's not working properly.
==========================
#!/bin/bash
HTTPD_LOGS_DIR=/scratch/co ntent/logs /apache # path to httpd log dir
YYMMDD=`/bin/date +%Y%m%d`
# This section will move Access Logs #
cd $HTTPD_LOGS_DIR/access
pwd
for i in `find . -name "*.$YYMMDD" -atime +0`
do
gzip $i
mv *.gz $HTTPD_LOGS_DIR/logs_backu p/.
done
========================== ========
Can any body suggest me a good Shell script to rotate the Apache logs...
Waiting for a quick Response....
Thanks
Deepak
I am facing lots of problem due to heavy logs generated by my Webserver.
I am using the following shell script to rotate the logs...but it's not working properly.
==========================
#!/bin/bash
HTTPD_LOGS_DIR=/scratch/co
YYMMDD=`/bin/date +%Y%m%d`
# This section will move Access Logs #
cd $HTTPD_LOGS_DIR/access
pwd
for i in `find . -name "*.$YYMMDD" -atime +0`
do
gzip $i
mv *.gz $HTTPD_LOGS_DIR/logs_backu
done
==========================
Can any body suggest me a good Shell script to rotate the Apache logs...
Waiting for a quick Response....
Thanks
Deepak
ASKER
Hi,
i have around 20 domains configured in a single box.
So separate logs are generate for separate Domains.
Log files are generated in different fashion as i have mentioned in the scripts...
So based on this i need a script to automate the proces....
Thanks
Deepak
i have around 20 domains configured in a single box.
So separate logs are generate for separate Domains.
Log files are generated in different fashion as i have mentioned in the scripts...
So based on this i need a script to automate the proces....
Thanks
Deepak
If you reload the webserver after you have archived the files your script should work. Some infomation might be lost during the time you started archiving and the reload of the webserver
ASKER
Problems i am facing from my existing scripts.....
1) Log files are created automatically once i delete the log files after i archive these logs.(without restarting apache)
2) sometimes getting incorrect timestamp for the log files.
3) i tried "> logfile" option also without deleting the log files, but i didn't workout.
Etc......
Thanks
Deepak
1) Log files are created automatically once i delete the log files after i archive these logs.(without restarting apache)
2) sometimes getting incorrect timestamp for the log files.
3) i tried "> logfile" option also without deleting the log files, but i didn't workout.
Etc......
Thanks
Deepak
ASKER
1) Log files are not created automatically once i delete the log files after i archive these logs.(without restarting apache)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The last guy (cyb3rj0hn) has the correct answer: you should be using logrotate
ASKER
Hi John,
here i am putting the access log line from my httpd.conf file.....
-------------------------- ---------- ---------- ---------- ---------- ------
CustomLog "| /apps/apache/2.0.48/bin/ro tatelogs /data/access/abc.com_acces s.%Y%m%d 86400" common
-------------------------- ---------- ---------- ---------- ---------- ------
above line create access log for abc.com in the format "abc.com_access.20041217"
so daily one log file is created for this domain.
Requirement :
i want to compress and move all logs to different folder(ex: /data/log_backup ) except current date logs and also delete all
logs from "/data/log_backup" folder which are 7 days old.
I guess this will not work out for me, so i have to remove "rotatelogs" implementation from httpd.conf file and follow your technique.
i have some doubts....
1) is "logrotate" calles to "/etc/logrotate.conf" file ?
2) shall i write a script file which will implement "logrotate" and call that script file in crontab ?
Still in Doubt...
Please give me the steps to implement "logrotate" and "logrotate.conf" for this...
Thanks
Deepak
here i am putting the access log line from my httpd.conf file.....
--------------------------
CustomLog "| /apps/apache/2.0.48/bin/ro
--------------------------
above line create access log for abc.com in the format "abc.com_access.20041217"
so daily one log file is created for this domain.
Requirement :
i want to compress and move all logs to different folder(ex: /data/log_backup ) except current date logs and also delete all
logs from "/data/log_backup" folder which are 7 days old.
I guess this will not work out for me, so i have to remove "rotatelogs" implementation from httpd.conf file and follow your technique.
i have some doubts....
1) is "logrotate" calles to "/etc/logrotate.conf" file ?
2) shall i write a script file which will implement "logrotate" and call that script file in crontab ?
Still in Doubt...
Please give me the steps to implement "logrotate" and "logrotate.conf" for this...
Thanks
Deepak
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I agree with hernst42.
ASKER
Thanks for all your help....
You can use the rotatelogs(2) command that comnes with apache(2) to write to the logfile. After logrotet has begun a new file you can zip the old one. If you change a log-file manual you need to reload the webserver so he closes the old file-pointer and starts with a new one. That might be your problem with your script.
Cheers!